Eugene Zelenko | 21fadad | 2017-11-21 23:26:08 +0000 | [diff] [blame] | 1 | //===- TemplateBase.cpp - Common template AST class implementation --------===// |
John McCall | 588d2d5 | 2009-10-29 07:48:15 +0000 | [diff] [blame] | 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 | // |
| 10 | // This file implements common classes used throughout C++ template |
| 11 | // representations. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
John McCall | 588d2d5 | 2009-10-29 07:48:15 +0000 | [diff] [blame] | 15 | #include "clang/AST/TemplateBase.h" |
Douglas Gregor | 0192c23 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
Eugene Zelenko | 21fadad | 2017-11-21 23:26:08 +0000 | [diff] [blame] | 17 | #include "clang/AST/Decl.h" |
John McCall | 588d2d5 | 2009-10-29 07:48:15 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclBase.h" |
Douglas Gregor | bd866c2 | 2009-11-23 12:52:47 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclTemplate.h" |
John McCall | 588d2d5 | 2009-10-29 07:48:15 +0000 | [diff] [blame] | 20 | #include "clang/AST/Expr.h" |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 21 | #include "clang/AST/ExprCXX.h" |
Eugene Zelenko | 21fadad | 2017-11-21 23:26:08 +0000 | [diff] [blame] | 22 | #include "clang/AST/PrettyPrinter.h" |
| 23 | #include "clang/AST/TemplateName.h" |
Chandler Carruth | 4c4f8de | 2011-02-19 00:21:00 +0000 | [diff] [blame] | 24 | #include "clang/AST/Type.h" |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 25 | #include "clang/AST/TypeLoc.h" |
Douglas Gregor | 3626a5c | 2010-05-08 17:41:32 +0000 | [diff] [blame] | 26 | #include "clang/Basic/Diagnostic.h" |
Eugene Zelenko | 21fadad | 2017-11-21 23:26:08 +0000 | [diff] [blame] | 27 | #include "clang/Basic/LLVM.h" |
| 28 | #include "clang/Basic/LangOptions.h" |
| 29 | #include "clang/Basic/SourceLocation.h" |
| 30 | #include "llvm/ADT/APSInt.h" |
Douglas Gregor | 0192c23 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 31 | #include "llvm/ADT/FoldingSet.h" |
Eugene Zelenko | 21fadad | 2017-11-21 23:26:08 +0000 | [diff] [blame] | 32 | #include "llvm/ADT/None.h" |
Benjamin Kramer | 4903802 | 2012-02-04 13:45:25 +0000 | [diff] [blame] | 33 | #include "llvm/ADT/SmallString.h" |
Eugene Zelenko | 21fadad | 2017-11-21 23:26:08 +0000 | [diff] [blame] | 34 | #include "llvm/ADT/StringRef.h" |
| 35 | #include "llvm/Support/Casting.h" |
| 36 | #include "llvm/Support/Compiler.h" |
| 37 | #include "llvm/Support/ErrorHandling.h" |
Benjamin Kramer | 444a130 | 2012-12-01 17:12:56 +0000 | [diff] [blame] | 38 | #include "llvm/Support/raw_ostream.h" |
Eugene Zelenko | 21fadad | 2017-11-21 23:26:08 +0000 | [diff] [blame] | 39 | #include <cassert> |
| 40 | #include <cstddef> |
| 41 | #include <cstdint> |
| 42 | #include <cstring> |
John McCall | 588d2d5 | 2009-10-29 07:48:15 +0000 | [diff] [blame] | 43 | |
| 44 | using namespace clang; |
| 45 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 46 | /// Print a template integral argument value. |
Chandler Carruth | 4c4f8de | 2011-02-19 00:21:00 +0000 | [diff] [blame] | 47 | /// |
| 48 | /// \param TemplArg the TemplateArgument instance to print. |
| 49 | /// |
| 50 | /// \param Out the raw_ostream instance to use for printing. |
Will Wilson | 67c41ba | 2014-12-13 04:31:07 +0000 | [diff] [blame] | 51 | /// |
| 52 | /// \param Policy the printing policy for EnumConstantDecl printing. |
Chandler Carruth | 4c4f8de | 2011-02-19 00:21:00 +0000 | [diff] [blame] | 53 | static void printIntegral(const TemplateArgument &TemplArg, |
Will Wilson | 67c41ba | 2014-12-13 04:31:07 +0000 | [diff] [blame] | 54 | raw_ostream &Out, const PrintingPolicy& Policy) { |
Eugene Zelenko | 21fadad | 2017-11-21 23:26:08 +0000 | [diff] [blame] | 55 | const Type *T = TemplArg.getIntegralType().getTypePtr(); |
Benjamin Kramer | 6003ad5 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 56 | const llvm::APSInt &Val = TemplArg.getAsIntegral(); |
Chandler Carruth | 4c4f8de | 2011-02-19 00:21:00 +0000 | [diff] [blame] | 57 | |
Will Wilson | 70a1568 | 2014-12-13 04:38:19 +0000 | [diff] [blame] | 58 | if (const EnumType *ET = T->getAs<EnumType>()) { |
Will Wilson | 67c41ba | 2014-12-13 04:31:07 +0000 | [diff] [blame] | 59 | for (const EnumConstantDecl* ECD : ET->getDecl()->enumerators()) { |
Richard Trieu | 94a9ae7 | 2015-01-09 00:58:16 +0000 | [diff] [blame] | 60 | // In Sema::CheckTemplateArugment, enum template arguments value are |
| 61 | // extended to the size of the integer underlying the enum type. This |
| 62 | // may create a size difference between the enum value and template |
| 63 | // argument value, requiring isSameValue here instead of operator==. |
| 64 | if (llvm::APSInt::isSameValue(ECD->getInitVal(), Val)) { |
Will Wilson | 67c41ba | 2014-12-13 04:31:07 +0000 | [diff] [blame] | 65 | ECD->printQualifiedName(Out, Policy); |
| 66 | return; |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
Reid Kleckner | 6010338 | 2015-12-16 02:04:40 +0000 | [diff] [blame] | 71 | if (T->isBooleanType() && !Policy.MSVCFormatting) { |
Benjamin Kramer | 6003ad5 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 72 | Out << (Val.getBoolValue() ? "true" : "false"); |
Chandler Carruth | 4c4f8de | 2011-02-19 00:21:00 +0000 | [diff] [blame] | 73 | } else if (T->isCharType()) { |
Benjamin Kramer | 6003ad5 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 74 | const char Ch = Val.getZExtValue(); |
Chandler Carruth | 20d0fee | 2011-02-25 20:09:13 +0000 | [diff] [blame] | 75 | Out << ((Ch == '\'') ? "'\\" : "'"); |
Benjamin Kramer | 4903802 | 2012-02-04 13:45:25 +0000 | [diff] [blame] | 76 | Out.write_escaped(StringRef(&Ch, 1), /*UseHexEscapes=*/ true); |
Chandler Carruth | 20d0fee | 2011-02-25 20:09:13 +0000 | [diff] [blame] | 77 | Out << "'"; |
Chandler Carruth | 4c4f8de | 2011-02-19 00:21:00 +0000 | [diff] [blame] | 78 | } else { |
Benjamin Kramer | 6003ad5 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 79 | Out << Val; |
Chandler Carruth | 4c4f8de | 2011-02-19 00:21:00 +0000 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | |
John McCall | 588d2d5 | 2009-10-29 07:48:15 +0000 | [diff] [blame] | 83 | //===----------------------------------------------------------------------===// |
| 84 | // TemplateArgument Implementation |
| 85 | //===----------------------------------------------------------------------===// |
| 86 | |
Benjamin Kramer | 6003ad5 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 87 | TemplateArgument::TemplateArgument(ASTContext &Ctx, const llvm::APSInt &Value, |
Eli Friedman | 2d1611b | 2013-08-21 23:05:56 +0000 | [diff] [blame] | 88 | QualType Type) { |
| 89 | Integer.Kind = Integral; |
Benjamin Kramer | 6003ad5 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 90 | // Copy the APSInt value into our decomposed form. |
| 91 | Integer.BitWidth = Value.getBitWidth(); |
| 92 | Integer.IsUnsigned = Value.isUnsigned(); |
| 93 | // If the value is large, we have to get additional memory from the ASTContext |
Benjamin Kramer | 5d4cff7 | 2012-06-07 15:54:03 +0000 | [diff] [blame] | 94 | unsigned NumWords = Value.getNumWords(); |
| 95 | if (NumWords > 1) { |
| 96 | void *Mem = Ctx.Allocate(NumWords * sizeof(uint64_t)); |
| 97 | std::memcpy(Mem, Value.getRawData(), NumWords * sizeof(uint64_t)); |
Benjamin Kramer | 6003ad5 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 98 | Integer.pVal = static_cast<uint64_t *>(Mem); |
| 99 | } else { |
| 100 | Integer.VAL = Value.getZExtValue(); |
| 101 | } |
| 102 | |
| 103 | Integer.Type = Type.getAsOpaquePtr(); |
| 104 | } |
| 105 | |
Benjamin Kramer | cce6347 | 2015-08-05 09:40:22 +0000 | [diff] [blame] | 106 | TemplateArgument |
| 107 | TemplateArgument::CreatePackCopy(ASTContext &Context, |
| 108 | ArrayRef<TemplateArgument> Args) { |
| 109 | if (Args.empty()) |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 110 | return getEmptyPack(); |
Benjamin Kramer | cce6347 | 2015-08-05 09:40:22 +0000 | [diff] [blame] | 111 | |
| 112 | return TemplateArgument(Args.copy(Context)); |
Douglas Gregor | 74c6d19 | 2011-01-11 23:09:57 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 115 | bool TemplateArgument::isDependent() const { |
| 116 | switch (getKind()) { |
| 117 | case Null: |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 118 | llvm_unreachable("Should not have a NULL template argument"); |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 119 | |
| 120 | case Type: |
Richard Smith | bc2e971 | 2014-10-17 20:56:14 +0000 | [diff] [blame] | 121 | return getAsType()->isDependentType() || |
| 122 | isa<PackExpansionType>(getAsType()); |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 123 | |
| 124 | case Template: |
| 125 | return getAsTemplate().isDependent(); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 126 | |
| 127 | case TemplateExpansion: |
| 128 | return true; |
| 129 | |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 130 | case Declaration: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 131 | if (DeclContext *DC = dyn_cast<DeclContext>(getAsDecl())) |
| 132 | return DC->isDependentContext(); |
| 133 | return getAsDecl()->getDeclContext()->isDependentContext(); |
| 134 | |
| 135 | case NullPtr: |
Douglas Gregor | 31f55dc | 2012-04-06 22:40:38 +0000 | [diff] [blame] | 136 | return false; |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 137 | |
| 138 | case Integral: |
| 139 | // Never dependent |
| 140 | return false; |
| 141 | |
| 142 | case Expression: |
Richard Smith | bc2e971 | 2014-10-17 20:56:14 +0000 | [diff] [blame] | 143 | return (getAsExpr()->isTypeDependent() || getAsExpr()->isValueDependent() || |
| 144 | isa<PackExpansionExpr>(getAsExpr())); |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 145 | |
| 146 | case Pack: |
Aaron Ballman | 2a89e85 | 2014-07-15 21:32:31 +0000 | [diff] [blame] | 147 | for (const auto &P : pack_elements()) |
| 148 | if (P.isDependent()) |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 149 | return true; |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 150 | return false; |
| 151 | } |
| 152 | |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 153 | llvm_unreachable("Invalid TemplateArgument Kind!"); |
Douglas Gregor | a6e053e | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 156 | bool TemplateArgument::isInstantiationDependent() const { |
| 157 | switch (getKind()) { |
| 158 | case Null: |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 159 | llvm_unreachable("Should not have a NULL template argument"); |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 160 | |
| 161 | case Type: |
| 162 | return getAsType()->isInstantiationDependentType(); |
| 163 | |
| 164 | case Template: |
| 165 | return getAsTemplate().isInstantiationDependent(); |
| 166 | |
| 167 | case TemplateExpansion: |
| 168 | return true; |
| 169 | |
| 170 | case Declaration: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 171 | if (DeclContext *DC = dyn_cast<DeclContext>(getAsDecl())) |
| 172 | return DC->isDependentContext(); |
| 173 | return getAsDecl()->getDeclContext()->isDependentContext(); |
| 174 | |
| 175 | case NullPtr: |
Douglas Gregor | 31f55dc | 2012-04-06 22:40:38 +0000 | [diff] [blame] | 176 | return false; |
| 177 | |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 178 | case Integral: |
| 179 | // Never dependent |
| 180 | return false; |
| 181 | |
| 182 | case Expression: |
| 183 | return getAsExpr()->isInstantiationDependent(); |
| 184 | |
| 185 | case Pack: |
Aaron Ballman | 2a89e85 | 2014-07-15 21:32:31 +0000 | [diff] [blame] | 186 | for (const auto &P : pack_elements()) |
| 187 | if (P.isInstantiationDependent()) |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 188 | return true; |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 189 | return false; |
| 190 | } |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 191 | |
| 192 | llvm_unreachable("Invalid TemplateArgument Kind!"); |
Douglas Gregor | 678d76c | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 195 | bool TemplateArgument::isPackExpansion() const { |
| 196 | switch (getKind()) { |
| 197 | case Null: |
| 198 | case Declaration: |
| 199 | case Integral: |
| 200 | case Pack: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 201 | case Template: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 202 | case NullPtr: |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 203 | return false; |
| 204 | |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 205 | case TemplateExpansion: |
| 206 | return true; |
| 207 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 208 | case Type: |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 209 | return isa<PackExpansionType>(getAsType()); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 210 | |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 211 | case Expression: |
Douglas Gregor | e8e9dd6 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 212 | return isa<PackExpansionExpr>(getAsExpr()); |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 213 | } |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 214 | |
| 215 | llvm_unreachable("Invalid TemplateArgument Kind!"); |
Douglas Gregor | 840bd6c | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Douglas Gregor | 506bd56 | 2010-12-13 22:49:22 +0000 | [diff] [blame] | 218 | bool TemplateArgument::containsUnexpandedParameterPack() const { |
| 219 | switch (getKind()) { |
| 220 | case Null: |
| 221 | case Declaration: |
| 222 | case Integral: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 223 | case TemplateExpansion: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 224 | case NullPtr: |
Douglas Gregor | 506bd56 | 2010-12-13 22:49:22 +0000 | [diff] [blame] | 225 | break; |
| 226 | |
| 227 | case Type: |
| 228 | if (getAsType()->containsUnexpandedParameterPack()) |
| 229 | return true; |
| 230 | break; |
| 231 | |
| 232 | case Template: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 233 | if (getAsTemplate().containsUnexpandedParameterPack()) |
Douglas Gregor | 506bd56 | 2010-12-13 22:49:22 +0000 | [diff] [blame] | 234 | return true; |
| 235 | break; |
| 236 | |
| 237 | case Expression: |
| 238 | if (getAsExpr()->containsUnexpandedParameterPack()) |
| 239 | return true; |
| 240 | break; |
| 241 | |
| 242 | case Pack: |
Aaron Ballman | 2a89e85 | 2014-07-15 21:32:31 +0000 | [diff] [blame] | 243 | for (const auto &P : pack_elements()) |
| 244 | if (P.containsUnexpandedParameterPack()) |
Douglas Gregor | 506bd56 | 2010-12-13 22:49:22 +0000 | [diff] [blame] | 245 | return true; |
| 246 | |
| 247 | break; |
| 248 | } |
| 249 | |
| 250 | return false; |
| 251 | } |
| 252 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 253 | Optional<unsigned> TemplateArgument::getNumTemplateExpansions() const { |
Eli Friedman | 2d1611b | 2013-08-21 23:05:56 +0000 | [diff] [blame] | 254 | assert(getKind() == TemplateExpansion); |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 255 | if (TemplateArg.NumExpansions) |
| 256 | return TemplateArg.NumExpansions - 1; |
| 257 | |
David Blaikie | 7a30dc5 | 2013-02-21 01:47:18 +0000 | [diff] [blame] | 258 | return None; |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 259 | } |
| 260 | |
Richard Smith | 593d6a1 | 2016-12-23 01:30:39 +0000 | [diff] [blame] | 261 | QualType TemplateArgument::getNonTypeTemplateArgumentType() const { |
| 262 | switch (getKind()) { |
| 263 | case TemplateArgument::Null: |
| 264 | case TemplateArgument::Type: |
| 265 | case TemplateArgument::Template: |
| 266 | case TemplateArgument::TemplateExpansion: |
| 267 | case TemplateArgument::Pack: |
| 268 | return QualType(); |
| 269 | |
| 270 | case TemplateArgument::Integral: |
| 271 | return getIntegralType(); |
| 272 | |
| 273 | case TemplateArgument::Expression: |
| 274 | return getAsExpr()->getType(); |
| 275 | |
| 276 | case TemplateArgument::Declaration: |
| 277 | return getParamTypeForDecl(); |
| 278 | |
| 279 | case TemplateArgument::NullPtr: |
| 280 | return getNullPtrType(); |
| 281 | } |
| 282 | |
| 283 | llvm_unreachable("Invalid TemplateArgument Kind!"); |
| 284 | } |
| 285 | |
John McCall | 588d2d5 | 2009-10-29 07:48:15 +0000 | [diff] [blame] | 286 | void TemplateArgument::Profile(llvm::FoldingSetNodeID &ID, |
Jay Foad | 39c7980 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 287 | const ASTContext &Context) const { |
Eli Friedman | 2d1611b | 2013-08-21 23:05:56 +0000 | [diff] [blame] | 288 | ID.AddInteger(getKind()); |
| 289 | switch (getKind()) { |
John McCall | 588d2d5 | 2009-10-29 07:48:15 +0000 | [diff] [blame] | 290 | case Null: |
| 291 | break; |
| 292 | |
| 293 | case Type: |
| 294 | getAsType().Profile(ID); |
| 295 | break; |
| 296 | |
Eli Friedman | 2d1611b | 2013-08-21 23:05:56 +0000 | [diff] [blame] | 297 | case NullPtr: |
| 298 | getNullPtrType().Profile(ID); |
| 299 | break; |
| 300 | |
John McCall | 588d2d5 | 2009-10-29 07:48:15 +0000 | [diff] [blame] | 301 | case Declaration: |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 302 | ID.AddPointer(getAsDecl()? getAsDecl()->getCanonicalDecl() : nullptr); |
John McCall | 588d2d5 | 2009-10-29 07:48:15 +0000 | [diff] [blame] | 303 | break; |
| 304 | |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 305 | case Template: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 306 | case TemplateExpansion: { |
| 307 | TemplateName Template = getAsTemplateOrTemplatePattern(); |
Douglas Gregor | bd866c2 | 2009-11-23 12:52:47 +0000 | [diff] [blame] | 308 | if (TemplateTemplateParmDecl *TTP |
| 309 | = dyn_cast_or_null<TemplateTemplateParmDecl>( |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 310 | Template.getAsTemplateDecl())) { |
Douglas Gregor | bd866c2 | 2009-11-23 12:52:47 +0000 | [diff] [blame] | 311 | ID.AddBoolean(true); |
| 312 | ID.AddInteger(TTP->getDepth()); |
| 313 | ID.AddInteger(TTP->getPosition()); |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 314 | ID.AddBoolean(TTP->isParameterPack()); |
Douglas Gregor | bd866c2 | 2009-11-23 12:52:47 +0000 | [diff] [blame] | 315 | } else { |
| 316 | ID.AddBoolean(false); |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 317 | ID.AddPointer(Context.getCanonicalTemplateName(Template) |
| 318 | .getAsVoidPointer()); |
Douglas Gregor | bd866c2 | 2009-11-23 12:52:47 +0000 | [diff] [blame] | 319 | } |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 320 | break; |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 321 | } |
Douglas Gregor | 9167f8b | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 322 | |
John McCall | 588d2d5 | 2009-10-29 07:48:15 +0000 | [diff] [blame] | 323 | case Integral: |
Benjamin Kramer | 6003ad5 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 324 | getAsIntegral().Profile(ID); |
John McCall | 588d2d5 | 2009-10-29 07:48:15 +0000 | [diff] [blame] | 325 | getIntegralType().Profile(ID); |
| 326 | break; |
| 327 | |
| 328 | case Expression: |
| 329 | getAsExpr()->Profile(ID, Context, true); |
| 330 | break; |
| 331 | |
| 332 | case Pack: |
| 333 | ID.AddInteger(Args.NumArgs); |
| 334 | for (unsigned I = 0; I != Args.NumArgs; ++I) |
| 335 | Args.Args[I].Profile(ID, Context); |
| 336 | } |
| 337 | } |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 338 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 339 | bool TemplateArgument::structurallyEquals(const TemplateArgument &Other) const { |
| 340 | if (getKind() != Other.getKind()) return false; |
| 341 | |
| 342 | switch (getKind()) { |
| 343 | case Null: |
| 344 | case Type: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 345 | case Expression: |
| 346 | case Template: |
| 347 | case TemplateExpansion: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 348 | case NullPtr: |
Eli Friedman | 2d1611b | 2013-08-21 23:05:56 +0000 | [diff] [blame] | 349 | return TypeOrValue.V == Other.TypeOrValue.V; |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 350 | |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 351 | case Declaration: |
David Blaikie | 0f62c8d | 2014-10-16 04:21:25 +0000 | [diff] [blame] | 352 | return getAsDecl() == Other.getAsDecl(); |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 353 | |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 354 | case Integral: |
| 355 | return getIntegralType() == Other.getIntegralType() && |
Benjamin Kramer | 6003ad5 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 356 | getAsIntegral() == Other.getAsIntegral(); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 357 | |
| 358 | case Pack: |
| 359 | if (Args.NumArgs != Other.Args.NumArgs) return false; |
| 360 | for (unsigned I = 0, E = Args.NumArgs; I != E; ++I) |
| 361 | if (!Args.Args[I].structurallyEquals(Other.Args.Args[I])) |
| 362 | return false; |
| 363 | return true; |
| 364 | } |
| 365 | |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 366 | llvm_unreachable("Invalid TemplateArgument Kind!"); |
John McCall | c392f37 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 367 | } |
| 368 | |
Douglas Gregor | 0f3feb4 | 2010-12-22 21:19:48 +0000 | [diff] [blame] | 369 | TemplateArgument TemplateArgument::getPackExpansionPattern() const { |
| 370 | assert(isPackExpansion()); |
| 371 | |
| 372 | switch (getKind()) { |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 373 | case Type: |
| 374 | return getAsType()->getAs<PackExpansionType>()->getPattern(); |
| 375 | |
| 376 | case Expression: |
| 377 | return cast<PackExpansionExpr>(getAsExpr())->getPattern(); |
| 378 | |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 379 | case TemplateExpansion: |
Douglas Gregor | e1d60df | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 380 | return TemplateArgument(getAsTemplateOrTemplatePattern()); |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 381 | |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 382 | case Declaration: |
| 383 | case Integral: |
| 384 | case Pack: |
| 385 | case Null: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 386 | case Template: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 387 | case NullPtr: |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 388 | return TemplateArgument(); |
Douglas Gregor | 0f3feb4 | 2010-12-22 21:19:48 +0000 | [diff] [blame] | 389 | } |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 390 | |
| 391 | llvm_unreachable("Invalid TemplateArgument Kind!"); |
Douglas Gregor | 0f3feb4 | 2010-12-22 21:19:48 +0000 | [diff] [blame] | 392 | } |
| 393 | |
Douglas Gregor | 0192c23 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 394 | void TemplateArgument::print(const PrintingPolicy &Policy, |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 395 | raw_ostream &Out) const { |
Douglas Gregor | 0192c23 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 396 | switch (getKind()) { |
| 397 | case Null: |
David Blaikie | abe1a39 | 2014-04-02 05:58:29 +0000 | [diff] [blame] | 398 | Out << "(no value)"; |
Douglas Gregor | 0192c23 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 399 | break; |
| 400 | |
| 401 | case Type: { |
Douglas Gregor | e46db90 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 402 | PrintingPolicy SubPolicy(Policy); |
| 403 | SubPolicy.SuppressStrongLifetime = true; |
Benjamin Kramer | 9170e91 | 2013-02-22 15:46:01 +0000 | [diff] [blame] | 404 | getAsType().print(Out, SubPolicy); |
Douglas Gregor | 0192c23 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 405 | break; |
| 406 | } |
| 407 | |
| 408 | case Declaration: { |
George Burgess IV | 00f70bd | 2018-03-01 05:43:23 +0000 | [diff] [blame] | 409 | NamedDecl *ND = getAsDecl(); |
David Blaikie | b8f6a8a | 2013-05-09 22:43:45 +0000 | [diff] [blame] | 410 | Out << '&'; |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 411 | if (ND->getDeclName()) { |
| 412 | // FIXME: distinguish between pointer and reference args? |
David Blaikie | b8f6a8a | 2013-05-09 22:43:45 +0000 | [diff] [blame] | 413 | ND->printQualifiedName(Out); |
Douglas Gregor | 31f55dc | 2012-04-06 22:40:38 +0000 | [diff] [blame] | 414 | } else { |
David Blaikie | abe1a39 | 2014-04-02 05:58:29 +0000 | [diff] [blame] | 415 | Out << "(anonymous)"; |
Douglas Gregor | 0192c23 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 416 | } |
| 417 | break; |
| 418 | } |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 419 | |
Abramo Bagnara | 4910701 | 2012-10-05 04:43:29 +0000 | [diff] [blame] | 420 | case NullPtr: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 421 | Out << "nullptr"; |
Abramo Bagnara | 4910701 | 2012-10-05 04:43:29 +0000 | [diff] [blame] | 422 | break; |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 423 | |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 424 | case Template: |
Douglas Gregor | 0192c23 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 425 | getAsTemplate().print(Out, Policy); |
| 426 | break; |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 427 | |
| 428 | case TemplateExpansion: |
| 429 | getAsTemplateOrTemplatePattern().print(Out, Policy); |
| 430 | Out << "..."; |
| 431 | break; |
| 432 | |
Eugene Zelenko | 21fadad | 2017-11-21 23:26:08 +0000 | [diff] [blame] | 433 | case Integral: |
Will Wilson | 67c41ba | 2014-12-13 04:31:07 +0000 | [diff] [blame] | 434 | printIntegral(*this, Out, Policy); |
Douglas Gregor | 0192c23 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 435 | break; |
Douglas Gregor | 0192c23 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 436 | |
Douglas Gregor | eb29d18 | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 437 | case Expression: |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 438 | getAsExpr()->printPretty(Out, nullptr, Policy); |
Douglas Gregor | 0192c23 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 439 | break; |
Douglas Gregor | 0192c23 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 440 | |
| 441 | case Pack: |
| 442 | Out << "<"; |
| 443 | bool First = true; |
Aaron Ballman | 2a89e85 | 2014-07-15 21:32:31 +0000 | [diff] [blame] | 444 | for (const auto &P : pack_elements()) { |
Douglas Gregor | 0192c23 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 445 | if (First) |
| 446 | First = false; |
| 447 | else |
| 448 | Out << ", "; |
| 449 | |
Aaron Ballman | 2a89e85 | 2014-07-15 21:32:31 +0000 | [diff] [blame] | 450 | P.print(Policy, Out); |
Douglas Gregor | 0192c23 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 451 | } |
| 452 | Out << ">"; |
| 453 | break; |
| 454 | } |
| 455 | } |
| 456 | |
Yaron Keren | c6d8a57 | 2016-01-29 13:46:15 +0000 | [diff] [blame] | 457 | void TemplateArgument::dump(raw_ostream &Out) const { |
| 458 | LangOptions LO; // FIXME! see also TemplateName::dump(). |
| 459 | LO.CPlusPlus = true; |
| 460 | LO.Bool = true; |
| 461 | print(PrintingPolicy(LO), Out); |
| 462 | } |
| 463 | |
Yaron Keren | cdae941 | 2016-01-29 19:38:18 +0000 | [diff] [blame] | 464 | LLVM_DUMP_METHOD void TemplateArgument::dump() const { dump(llvm::errs()); } |
Yaron Keren | c6d8a57 | 2016-01-29 13:46:15 +0000 | [diff] [blame] | 465 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 466 | //===----------------------------------------------------------------------===// |
| 467 | // TemplateArgumentLoc Implementation |
| 468 | //===----------------------------------------------------------------------===// |
| 469 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 470 | SourceRange TemplateArgumentLoc::getSourceRange() const { |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 471 | switch (Argument.getKind()) { |
| 472 | case TemplateArgument::Expression: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 473 | return getSourceExpression()->getSourceRange(); |
Zhanyong Wan | 18ca8bf | 2010-09-03 23:50:56 +0000 | [diff] [blame] | 474 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 475 | case TemplateArgument::Declaration: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 476 | return getSourceDeclExpression()->getSourceRange(); |
Zhanyong Wan | 18ca8bf | 2010-09-03 23:50:56 +0000 | [diff] [blame] | 477 | |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 478 | case TemplateArgument::NullPtr: |
| 479 | return getSourceNullPtrExpression()->getSourceRange(); |
| 480 | |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 481 | case TemplateArgument::Type: |
Zhanyong Wan | 18ca8bf | 2010-09-03 23:50:56 +0000 | [diff] [blame] | 482 | if (TypeSourceInfo *TSI = getTypeSourceInfo()) |
| 483 | return TSI->getTypeLoc().getSourceRange(); |
| 484 | else |
| 485 | return SourceRange(); |
| 486 | |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 487 | case TemplateArgument::Template: |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 488 | if (getTemplateQualifierLoc()) |
| 489 | return SourceRange(getTemplateQualifierLoc().getBeginLoc(), |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 490 | getTemplateNameLoc()); |
| 491 | return SourceRange(getTemplateNameLoc()); |
| 492 | |
| 493 | case TemplateArgument::TemplateExpansion: |
Douglas Gregor | 9d80212 | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 494 | if (getTemplateQualifierLoc()) |
| 495 | return SourceRange(getTemplateQualifierLoc().getBeginLoc(), |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 496 | getTemplateEllipsisLoc()); |
| 497 | return SourceRange(getTemplateNameLoc(), getTemplateEllipsisLoc()); |
| 498 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 499 | case TemplateArgument::Integral: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 500 | return getSourceIntegralExpression()->getSourceRange(); |
| 501 | |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 502 | case TemplateArgument::Pack: |
| 503 | case TemplateArgument::Null: |
John McCall | 0d07eb3 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 504 | return SourceRange(); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 505 | } |
| 506 | |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 507 | llvm_unreachable("Invalid TemplateArgument Kind!"); |
John McCall | 0ad1666 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 508 | } |
Douglas Gregor | 3626a5c | 2010-05-08 17:41:32 +0000 | [diff] [blame] | 509 | |
| 510 | const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB, |
| 511 | const TemplateArgument &Arg) { |
| 512 | switch (Arg.getKind()) { |
| 513 | case TemplateArgument::Null: |
John McCall | 3b3a5ed | 2010-08-05 04:58:04 +0000 | [diff] [blame] | 514 | // This is bad, but not as bad as crashing because of argument |
| 515 | // count mismatches. |
| 516 | return DB << "(null template argument)"; |
Douglas Gregor | 3626a5c | 2010-05-08 17:41:32 +0000 | [diff] [blame] | 517 | |
| 518 | case TemplateArgument::Type: |
| 519 | return DB << Arg.getAsType(); |
| 520 | |
| 521 | case TemplateArgument::Declaration: |
Eli Friedman | b826a00 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 522 | return DB << Arg.getAsDecl(); |
| 523 | |
| 524 | case TemplateArgument::NullPtr: |
Douglas Gregor | 31f55dc | 2012-04-06 22:40:38 +0000 | [diff] [blame] | 525 | return DB << "nullptr"; |
Douglas Gregor | 3626a5c | 2010-05-08 17:41:32 +0000 | [diff] [blame] | 526 | |
| 527 | case TemplateArgument::Integral: |
Benjamin Kramer | 6003ad5 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 528 | return DB << Arg.getAsIntegral().toString(10); |
Douglas Gregor | 3626a5c | 2010-05-08 17:41:32 +0000 | [diff] [blame] | 529 | |
| 530 | case TemplateArgument::Template: |
Douglas Gregor | e4ff4b5 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 531 | return DB << Arg.getAsTemplate(); |
| 532 | |
| 533 | case TemplateArgument::TemplateExpansion: |
| 534 | return DB << Arg.getAsTemplateOrTemplatePattern() << "..."; |
| 535 | |
Douglas Gregor | 3626a5c | 2010-05-08 17:41:32 +0000 | [diff] [blame] | 536 | case TemplateArgument::Expression: { |
| 537 | // This shouldn't actually ever happen, so it's okay that we're |
| 538 | // regurgitating an expression here. |
| 539 | // FIXME: We're guessing at LangOptions! |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 540 | SmallString<32> Str; |
Douglas Gregor | 3626a5c | 2010-05-08 17:41:32 +0000 | [diff] [blame] | 541 | llvm::raw_svector_ostream OS(Str); |
| 542 | LangOptions LangOpts; |
| 543 | LangOpts.CPlusPlus = true; |
| 544 | PrintingPolicy Policy(LangOpts); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 545 | Arg.getAsExpr()->printPretty(OS, nullptr, Policy); |
Douglas Gregor | 3626a5c | 2010-05-08 17:41:32 +0000 | [diff] [blame] | 546 | return DB << OS.str(); |
| 547 | } |
| 548 | |
Douglas Gregor | 0192c23 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 549 | case TemplateArgument::Pack: { |
| 550 | // FIXME: We're guessing at LangOptions! |
Dylan Noblesmith | 2c1dd27 | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 551 | SmallString<32> Str; |
Douglas Gregor | 0192c23 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 552 | llvm::raw_svector_ostream OS(Str); |
| 553 | LangOptions LangOpts; |
| 554 | LangOpts.CPlusPlus = true; |
| 555 | PrintingPolicy Policy(LangOpts); |
| 556 | Arg.print(Policy, OS); |
| 557 | return DB << OS.str(); |
| 558 | } |
Douglas Gregor | 3626a5c | 2010-05-08 17:41:32 +0000 | [diff] [blame] | 559 | } |
David Blaikie | e4d798f | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 560 | |
| 561 | llvm_unreachable("Invalid TemplateArgument Kind!"); |
Douglas Gregor | 3626a5c | 2010-05-08 17:41:32 +0000 | [diff] [blame] | 562 | } |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 563 | |
| 564 | const ASTTemplateArgumentListInfo * |
| 565 | ASTTemplateArgumentListInfo::Create(ASTContext &C, |
| 566 | const TemplateArgumentListInfo &List) { |
James Y Knight | 04ec5bf | 2015-12-24 02:59:37 +0000 | [diff] [blame] | 567 | std::size_t size = totalSizeToAlloc<TemplateArgumentLoc>(List.size()); |
Benjamin Kramer | c3f8925 | 2016-10-20 14:27:22 +0000 | [diff] [blame] | 568 | void *Mem = C.Allocate(size, alignof(ASTTemplateArgumentListInfo)); |
James Y Knight | 04ec5bf | 2015-12-24 02:59:37 +0000 | [diff] [blame] | 569 | return new (Mem) ASTTemplateArgumentListInfo(List); |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 570 | } |
| 571 | |
James Y Knight | 04ec5bf | 2015-12-24 02:59:37 +0000 | [diff] [blame] | 572 | ASTTemplateArgumentListInfo::ASTTemplateArgumentListInfo( |
| 573 | const TemplateArgumentListInfo &Info) { |
| 574 | LAngleLoc = Info.getLAngleLoc(); |
| 575 | RAngleLoc = Info.getRAngleLoc(); |
| 576 | NumTemplateArgs = Info.size(); |
| 577 | |
| 578 | TemplateArgumentLoc *ArgBuffer = getTrailingObjects<TemplateArgumentLoc>(); |
| 579 | for (unsigned i = 0; i != NumTemplateArgs; ++i) |
| 580 | new (&ArgBuffer[i]) TemplateArgumentLoc(Info[i]); |
| 581 | } |
| 582 | |
| 583 | void ASTTemplateKWAndArgsInfo::initializeFrom( |
James Y Knight | e7d8228 | 2015-12-29 18:15:14 +0000 | [diff] [blame] | 584 | SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &Info, |
| 585 | TemplateArgumentLoc *OutArgArray) { |
James Y Knight | 04ec5bf | 2015-12-24 02:59:37 +0000 | [diff] [blame] | 586 | this->TemplateKWLoc = TemplateKWLoc; |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 587 | LAngleLoc = Info.getLAngleLoc(); |
| 588 | RAngleLoc = Info.getRAngleLoc(); |
| 589 | NumTemplateArgs = Info.size(); |
| 590 | |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 591 | for (unsigned i = 0; i != NumTemplateArgs; ++i) |
James Y Knight | e7d8228 | 2015-12-29 18:15:14 +0000 | [diff] [blame] | 592 | new (&OutArgArray[i]) TemplateArgumentLoc(Info[i]); |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 593 | } |
| 594 | |
James Y Knight | 04ec5bf | 2015-12-24 02:59:37 +0000 | [diff] [blame] | 595 | void ASTTemplateKWAndArgsInfo::initializeFrom(SourceLocation TemplateKWLoc) { |
| 596 | assert(TemplateKWLoc.isValid()); |
| 597 | LAngleLoc = SourceLocation(); |
| 598 | RAngleLoc = SourceLocation(); |
| 599 | this->TemplateKWLoc = TemplateKWLoc; |
| 600 | NumTemplateArgs = 0; |
| 601 | } |
| 602 | |
| 603 | void ASTTemplateKWAndArgsInfo::initializeFrom( |
| 604 | SourceLocation TemplateKWLoc, const TemplateArgumentListInfo &Info, |
James Y Knight | e7d8228 | 2015-12-29 18:15:14 +0000 | [diff] [blame] | 605 | TemplateArgumentLoc *OutArgArray, bool &Dependent, |
| 606 | bool &InstantiationDependent, bool &ContainsUnexpandedParameterPack) { |
James Y Knight | 04ec5bf | 2015-12-24 02:59:37 +0000 | [diff] [blame] | 607 | this->TemplateKWLoc = TemplateKWLoc; |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 608 | LAngleLoc = Info.getLAngleLoc(); |
| 609 | RAngleLoc = Info.getRAngleLoc(); |
| 610 | NumTemplateArgs = Info.size(); |
| 611 | |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 612 | for (unsigned i = 0; i != NumTemplateArgs; ++i) { |
| 613 | Dependent = Dependent || Info[i].getArgument().isDependent(); |
James Y Knight | 04ec5bf | 2015-12-24 02:59:37 +0000 | [diff] [blame] | 614 | InstantiationDependent = InstantiationDependent || |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 615 | Info[i].getArgument().isInstantiationDependent(); |
James Y Knight | 04ec5bf | 2015-12-24 02:59:37 +0000 | [diff] [blame] | 616 | ContainsUnexpandedParameterPack = |
| 617 | ContainsUnexpandedParameterPack || |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 618 | Info[i].getArgument().containsUnexpandedParameterPack(); |
| 619 | |
James Y Knight | e7d8228 | 2015-12-29 18:15:14 +0000 | [diff] [blame] | 620 | new (&OutArgArray[i]) TemplateArgumentLoc(Info[i]); |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 621 | } |
| 622 | } |
| 623 | |
James Y Knight | e7d8228 | 2015-12-29 18:15:14 +0000 | [diff] [blame] | 624 | void ASTTemplateKWAndArgsInfo::copyInto(const TemplateArgumentLoc *ArgArray, |
| 625 | TemplateArgumentListInfo &Info) const { |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 626 | Info.setLAngleLoc(LAngleLoc); |
| 627 | Info.setRAngleLoc(RAngleLoc); |
| 628 | for (unsigned I = 0; I != NumTemplateArgs; ++I) |
James Y Knight | e7d8228 | 2015-12-29 18:15:14 +0000 | [diff] [blame] | 629 | Info.addArgument(ArgArray[I]); |
Abramo Bagnara | 7945c98 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 630 | } |