TemplateDeduction.h revision fc8f0e14ad142ed811e90fbd9a30e419e301c717
1a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch//===- TemplateDeduction.h - C++ template argument deduction ----*- C++ -*-===/ 2a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// 3a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// The LLVM Compiler Infrastructure 4a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// 55f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// This file is distributed under the University of Illinois Open Source 6a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// License. See LICENSE.TXT for details. 75c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu//===----------------------------------------------------------------------===/ 8116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// 95f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// This file provides types used with Sema's template argument deduction 10a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// routines. 11a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch// 12a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch//===----------------------------------------------------------------------===/ 13a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#ifndef LLVM_CLANG_SEMA_TEMPLATE_DEDUCTION_H 14a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#define LLVM_CLANG_SEMA_TEMPLATE_DEDUCTION_H 15a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 16a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "clang/Basic/PartialDiagnostic.h" 17a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "clang/AST/DeclTemplate.h" 18a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#include "llvm/ADT/SmallVector.h" 19a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 20a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochnamespace clang { 21a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 22a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochclass ASTContext; 23a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochclass TemplateArgumentList; 24a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 25a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochnamespace sema { 26a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 27cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)/// \brief Provides information about an attempted template argument 28a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch/// deduction, whose success or failure was described by a 29a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch/// TemplateDeductionResult value. 30a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochclass TemplateDeductionInfo { 31a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch /// \brief The context in which the template arguments are stored. 32a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch ASTContext &Context; 33a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 34a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch /// \brief The deduced template argument list. 35a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch /// 36a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch TemplateArgumentList *Deduced; 37a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 38a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch /// \brief The source location at which template argument 39a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch /// deduction is occurring. 405c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu SourceLocation Loc; 415c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 42116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch /// \brief Warnings (and follow-on notes) that were suppressed due to 431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci /// SFINAE while performing template argument deduction. 445c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu llvm::SmallVector<PartialDiagnosticAt, 4> SuppressedDiagnostics; 455c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 465c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // do not implement these 475c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu TemplateDeductionInfo(const TemplateDeductionInfo&); 485c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu TemplateDeductionInfo &operator=(const TemplateDeductionInfo&); 495c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu 505c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liupublic: 51a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch TemplateDeductionInfo(ASTContext &Context, SourceLocation Loc) 52a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch : Context(Context), Deduced(0), Loc(Loc) { } 53a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 54a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch ~TemplateDeductionInfo() { 55a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch // FIXME: if (Deduced) Deduced->Destroy(Context); 56a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } 57a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch 58a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch /// \brief Returns the location at which template argument is 59a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch /// occurring. 60a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch SourceLocation getLocation() const { 61a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch return Loc; 62a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch } 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 llvm::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