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