TemplateDeduction.h revision 686775deca8b8685eb90801495880e3abdd844c2
1//===- TemplateDeduction.h - C++ template argument deduction ----*- C++ -*-===/ 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7//===----------------------------------------------------------------------===/ 8// 9// This file provides types used with Sema's template argument deduction 10// routines. 11// 12//===----------------------------------------------------------------------===/ 13#ifndef LLVM_CLANG_SEMA_TEMPLATE_DEDUCTION_H 14#define LLVM_CLANG_SEMA_TEMPLATE_DEDUCTION_H 15 16#include "clang/Basic/PartialDiagnostic.h" 17#include "clang/AST/DeclTemplate.h" 18#include "llvm/ADT/SmallVector.h" 19 20namespace clang { 21 22class ASTContext; 23class TemplateArgumentList; 24 25namespace sema { 26 27/// \brief Provides information about an attempted template argument 28/// deduction, whose success or failure was described by a 29/// TemplateDeductionResult value. 30class TemplateDeductionInfo { 31 /// \brief The context in which the template arguments are stored. 32 ASTContext &Context; 33 34 /// \brief The deduced template argument list. 35 /// 36 TemplateArgumentList *Deduced; 37 38 /// \brief The source location at which template argument 39 /// deduction is occurring. 40 SourceLocation Loc; 41 42 /// \brief Warnings (and follow-on notes) that were suppressed due to 43 /// SFINAE while performing template argument deduction. 44 SmallVector<PartialDiagnosticAt, 4> SuppressedDiagnostics; 45 46 // do not implement these 47 TemplateDeductionInfo(const TemplateDeductionInfo&); 48 TemplateDeductionInfo &operator=(const TemplateDeductionInfo&); 49 50public: 51 TemplateDeductionInfo(ASTContext &Context, SourceLocation Loc) 52 : Context(Context), Deduced(0), Loc(Loc) { } 53 54 ~TemplateDeductionInfo() { 55 // FIXME: if (Deduced) Deduced->Destroy(Context); 56 } 57 58 /// \brief Returns the location at which template argument is 59 /// occurring. 60 SourceLocation getLocation() const { 61 return Loc; 62 } 63 64 /// \brief Take ownership of the deduced template argument list. 65 TemplateArgumentList *take() { 66 TemplateArgumentList *Result = Deduced; 67 Deduced = 0; 68 return Result; 69 } 70 71 /// \brief Provide a new template argument list that contains the 72 /// results of template argument deduction. 73 void reset(TemplateArgumentList *NewDeduced) { 74 // FIXME: if (Deduced) Deduced->Destroy(Context); 75 Deduced = NewDeduced; 76 } 77 78 /// \brief Add a new diagnostic to the set of diagnostics 79 void addSuppressedDiagnostic(SourceLocation Loc, const PartialDiagnostic &PD) { 80 SuppressedDiagnostics.push_back(std::make_pair(Loc, PD)); 81 } 82 83 /// \brief Iterator over the set of suppressed diagnostics. 84 typedef SmallVectorImpl<PartialDiagnosticAt>::const_iterator 85 diag_iterator; 86 87 /// \brief Returns an iterator at the beginning of the sequence of suppressed 88 /// diagnostics. 89 diag_iterator diag_begin() const { return SuppressedDiagnostics.begin(); } 90 91 /// \brief Returns an iterator at the end of the sequence of suppressed 92 /// diagnostics. 93 diag_iterator diag_end() const { return SuppressedDiagnostics.end(); } 94 95 /// \brief The template parameter to which a template argument 96 /// deduction failure refers. 97 /// 98 /// Depending on the result of template argument deduction, this 99 /// template parameter may have different meanings: 100 /// 101 /// TDK_Incomplete: this is the first template parameter whose 102 /// corresponding template argument was not deduced. 103 /// 104 /// TDK_Inconsistent: this is the template parameter for which 105 /// two different template argument values were deduced. 106 TemplateParameter Param; 107 108 /// \brief The first template argument to which the template 109 /// argument deduction failure refers. 110 /// 111 /// Depending on the result of the template argument deduction, 112 /// this template argument may have different meanings: 113 /// 114 /// TDK_Inconsistent: this argument is the first value deduced 115 /// for the corresponding template parameter. 116 /// 117 /// TDK_SubstitutionFailure: this argument is the template 118 /// argument we were instantiating when we encountered an error. 119 /// 120 /// TDK_NonDeducedMismatch: this is the template argument 121 /// provided in the source code. 122 TemplateArgument FirstArg; 123 124 /// \brief The second template argument to which the template 125 /// argument deduction failure refers. 126 /// 127 /// FIXME: Finish documenting this. 128 TemplateArgument SecondArg; 129}; 130 131} 132} 133 134#endif 135