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 20 namespace clang { 21 22 class ASTContext; 23 class TemplateArgumentList; 24 25 namespace sema { 26 27 /// \brief Provides information about an attempted template argument 28 /// deduction, whose success or failure was described by a 29 /// TemplateDeductionResult value. 30 class 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 50 public: TemplateDeductionInfo(ASTContext & Context,SourceLocation Loc)51 TemplateDeductionInfo(ASTContext &Context, SourceLocation Loc) 52 : Context(Context), Deduced(0), Loc(Loc) { } 53 ~TemplateDeductionInfo()54 ~TemplateDeductionInfo() { 55 // FIXME: if (Deduced) Deduced->Destroy(Context); 56 } 57 58 /// \brief Returns the location at which template argument is 59 /// occurring. getLocation()60 SourceLocation getLocation() const { 61 return Loc; 62 } 63 64 /// \brief Take ownership of the deduced template argument list. take()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. reset(TemplateArgumentList * NewDeduced)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 addSuppressedDiagnostic(SourceLocation Loc,const PartialDiagnostic & PD)79 void addSuppressedDiagnostic(SourceLocation Loc, 80 const PartialDiagnostic &PD) { 81 SuppressedDiagnostics.push_back(std::make_pair(Loc, PD)); 82 } 83 84 /// \brief Iterator over the set of suppressed diagnostics. 85 typedef SmallVectorImpl<PartialDiagnosticAt>::const_iterator 86 diag_iterator; 87 88 /// \brief Returns an iterator at the beginning of the sequence of suppressed 89 /// diagnostics. diag_begin()90 diag_iterator diag_begin() const { return SuppressedDiagnostics.begin(); } 91 92 /// \brief Returns an iterator at the end of the sequence of suppressed 93 /// diagnostics. diag_end()94 diag_iterator diag_end() const { return SuppressedDiagnostics.end(); } 95 96 /// \brief The template parameter to which a template argument 97 /// deduction failure refers. 98 /// 99 /// Depending on the result of template argument deduction, this 100 /// template parameter may have different meanings: 101 /// 102 /// TDK_Incomplete: this is the first template parameter whose 103 /// corresponding template argument was not deduced. 104 /// 105 /// TDK_Inconsistent: this is the template parameter for which 106 /// two different template argument values were deduced. 107 TemplateParameter Param; 108 109 /// \brief The first template argument to which the template 110 /// argument deduction failure refers. 111 /// 112 /// Depending on the result of the template argument deduction, 113 /// this template argument may have different meanings: 114 /// 115 /// TDK_Inconsistent: this argument is the first value deduced 116 /// for the corresponding template parameter. 117 /// 118 /// TDK_SubstitutionFailure: this argument is the template 119 /// argument we were instantiating when we encountered an error. 120 /// 121 /// TDK_NonDeducedMismatch: this is the template argument 122 /// provided in the source code. 123 TemplateArgument FirstArg; 124 125 /// \brief The second template argument to which the template 126 /// argument deduction failure refers. 127 /// 128 /// FIXME: Finish documenting this. 129 TemplateArgument SecondArg; 130 }; 131 132 } 133 } 134 135 #endif 136