John McCall | 275c10a | 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 | 275c10a | 2009-10-29 07:48:15 +0000 | [diff] [blame] | 15 | #include "clang/AST/TemplateBase.h" |
Douglas Gregor | 87dd697 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
John McCall | 275c10a | 2009-10-29 07:48:15 +0000 | [diff] [blame] | 17 | #include "clang/AST/DeclBase.h" |
Douglas Gregor | 74295b3 | 2009-11-23 12:52:47 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclTemplate.h" |
John McCall | 275c10a | 2009-10-29 07:48:15 +0000 | [diff] [blame] | 19 | #include "clang/AST/Expr.h" |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 20 | #include "clang/AST/ExprCXX.h" |
Chandler Carruth | 781701c | 2011-02-19 00:21:00 +0000 | [diff] [blame] | 21 | #include "clang/AST/Type.h" |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 22 | #include "clang/AST/TypeLoc.h" |
Douglas Gregor | a933319 | 2010-05-08 17:41:32 +0000 | [diff] [blame] | 23 | #include "clang/Basic/Diagnostic.h" |
Douglas Gregor | 87dd697 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/FoldingSet.h" |
Benjamin Kramer | 8fe83e1 | 2012-02-04 13:45:25 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/SmallString.h" |
Benjamin Kramer | a93d0f2 | 2012-12-01 17:12:56 +0000 | [diff] [blame^] | 26 | #include "llvm/Support/raw_ostream.h" |
Douglas Gregor | 203e6a3 | 2011-01-11 23:09:57 +0000 | [diff] [blame] | 27 | #include <algorithm> |
Chandler Carruth | 781701c | 2011-02-19 00:21:00 +0000 | [diff] [blame] | 28 | #include <cctype> |
John McCall | 275c10a | 2009-10-29 07:48:15 +0000 | [diff] [blame] | 29 | |
| 30 | using namespace clang; |
| 31 | |
Chandler Carruth | 781701c | 2011-02-19 00:21:00 +0000 | [diff] [blame] | 32 | /// \brief Print a template integral argument value. |
| 33 | /// |
| 34 | /// \param TemplArg the TemplateArgument instance to print. |
| 35 | /// |
| 36 | /// \param Out the raw_ostream instance to use for printing. |
| 37 | static void printIntegral(const TemplateArgument &TemplArg, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 38 | raw_ostream &Out) { |
Chandler Carruth | 781701c | 2011-02-19 00:21:00 +0000 | [diff] [blame] | 39 | const ::clang::Type *T = TemplArg.getIntegralType().getTypePtr(); |
Benjamin Kramer | 8552437 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 40 | const llvm::APSInt &Val = TemplArg.getAsIntegral(); |
Chandler Carruth | 781701c | 2011-02-19 00:21:00 +0000 | [diff] [blame] | 41 | |
| 42 | if (T->isBooleanType()) { |
Benjamin Kramer | 8552437 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 43 | Out << (Val.getBoolValue() ? "true" : "false"); |
Chandler Carruth | 781701c | 2011-02-19 00:21:00 +0000 | [diff] [blame] | 44 | } else if (T->isCharType()) { |
Benjamin Kramer | 8552437 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 45 | const char Ch = Val.getZExtValue(); |
Chandler Carruth | 774e2b4 | 2011-02-25 20:09:13 +0000 | [diff] [blame] | 46 | Out << ((Ch == '\'') ? "'\\" : "'"); |
Benjamin Kramer | 8fe83e1 | 2012-02-04 13:45:25 +0000 | [diff] [blame] | 47 | Out.write_escaped(StringRef(&Ch, 1), /*UseHexEscapes=*/ true); |
Chandler Carruth | 774e2b4 | 2011-02-25 20:09:13 +0000 | [diff] [blame] | 48 | Out << "'"; |
Chandler Carruth | 781701c | 2011-02-19 00:21:00 +0000 | [diff] [blame] | 49 | } else { |
Benjamin Kramer | 8552437 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 50 | Out << Val; |
Chandler Carruth | 781701c | 2011-02-19 00:21:00 +0000 | [diff] [blame] | 51 | } |
| 52 | } |
| 53 | |
John McCall | 275c10a | 2009-10-29 07:48:15 +0000 | [diff] [blame] | 54 | //===----------------------------------------------------------------------===// |
| 55 | // TemplateArgument Implementation |
| 56 | //===----------------------------------------------------------------------===// |
| 57 | |
Benjamin Kramer | 8552437 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 58 | TemplateArgument::TemplateArgument(ASTContext &Ctx, const llvm::APSInt &Value, |
| 59 | QualType Type) |
| 60 | : Kind(Integral) { |
| 61 | // Copy the APSInt value into our decomposed form. |
| 62 | Integer.BitWidth = Value.getBitWidth(); |
| 63 | Integer.IsUnsigned = Value.isUnsigned(); |
| 64 | // If the value is large, we have to get additional memory from the ASTContext |
Benjamin Kramer | b8e54cd | 2012-06-07 15:54:03 +0000 | [diff] [blame] | 65 | unsigned NumWords = Value.getNumWords(); |
| 66 | if (NumWords > 1) { |
| 67 | void *Mem = Ctx.Allocate(NumWords * sizeof(uint64_t)); |
| 68 | std::memcpy(Mem, Value.getRawData(), NumWords * sizeof(uint64_t)); |
Benjamin Kramer | 8552437 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 69 | Integer.pVal = static_cast<uint64_t *>(Mem); |
| 70 | } else { |
| 71 | Integer.VAL = Value.getZExtValue(); |
| 72 | } |
| 73 | |
| 74 | Integer.Type = Type.getAsOpaquePtr(); |
| 75 | } |
| 76 | |
Douglas Gregor | 203e6a3 | 2011-01-11 23:09:57 +0000 | [diff] [blame] | 77 | TemplateArgument TemplateArgument::CreatePackCopy(ASTContext &Context, |
| 78 | const TemplateArgument *Args, |
| 79 | unsigned NumArgs) { |
| 80 | if (NumArgs == 0) |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 81 | return getEmptyPack(); |
Douglas Gregor | 203e6a3 | 2011-01-11 23:09:57 +0000 | [diff] [blame] | 82 | |
| 83 | TemplateArgument *Storage = new (Context) TemplateArgument [NumArgs]; |
| 84 | std::copy(Args, Args + NumArgs, Storage); |
| 85 | return TemplateArgument(Storage, NumArgs); |
| 86 | } |
| 87 | |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 88 | bool TemplateArgument::isDependent() const { |
| 89 | switch (getKind()) { |
| 90 | case Null: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 91 | llvm_unreachable("Should not have a NULL template argument"); |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 92 | |
| 93 | case Type: |
| 94 | return getAsType()->isDependentType(); |
| 95 | |
| 96 | case Template: |
| 97 | return getAsTemplate().isDependent(); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 98 | |
| 99 | case TemplateExpansion: |
| 100 | return true; |
| 101 | |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 102 | case Declaration: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 103 | if (DeclContext *DC = dyn_cast<DeclContext>(getAsDecl())) |
| 104 | return DC->isDependentContext(); |
| 105 | return getAsDecl()->getDeclContext()->isDependentContext(); |
| 106 | |
| 107 | case NullPtr: |
Douglas Gregor | d2008e2 | 2012-04-06 22:40:38 +0000 | [diff] [blame] | 108 | return false; |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 109 | |
| 110 | case Integral: |
| 111 | // Never dependent |
| 112 | return false; |
| 113 | |
| 114 | case Expression: |
| 115 | return (getAsExpr()->isTypeDependent() || getAsExpr()->isValueDependent()); |
| 116 | |
| 117 | case Pack: |
| 118 | for (pack_iterator P = pack_begin(), PEnd = pack_end(); P != PEnd; ++P) { |
| 119 | if (P->isDependent()) |
| 120 | return true; |
| 121 | } |
| 122 | |
| 123 | return false; |
| 124 | } |
| 125 | |
David Blaikie | 3026348 | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 126 | llvm_unreachable("Invalid TemplateArgument Kind!"); |
Douglas Gregor | bebbe0d | 2010-12-15 01:34:56 +0000 | [diff] [blame] | 127 | } |
| 128 | |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 129 | bool TemplateArgument::isInstantiationDependent() const { |
| 130 | switch (getKind()) { |
| 131 | case Null: |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 132 | llvm_unreachable("Should not have a NULL template argument"); |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 133 | |
| 134 | case Type: |
| 135 | return getAsType()->isInstantiationDependentType(); |
| 136 | |
| 137 | case Template: |
| 138 | return getAsTemplate().isInstantiationDependent(); |
| 139 | |
| 140 | case TemplateExpansion: |
| 141 | return true; |
| 142 | |
| 143 | case Declaration: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 144 | if (DeclContext *DC = dyn_cast<DeclContext>(getAsDecl())) |
| 145 | return DC->isDependentContext(); |
| 146 | return getAsDecl()->getDeclContext()->isDependentContext(); |
| 147 | |
| 148 | case NullPtr: |
Douglas Gregor | d2008e2 | 2012-04-06 22:40:38 +0000 | [diff] [blame] | 149 | return false; |
| 150 | |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 151 | case Integral: |
| 152 | // Never dependent |
| 153 | return false; |
| 154 | |
| 155 | case Expression: |
| 156 | return getAsExpr()->isInstantiationDependent(); |
| 157 | |
| 158 | case Pack: |
| 159 | for (pack_iterator P = pack_begin(), PEnd = pack_end(); P != PEnd; ++P) { |
| 160 | if (P->isInstantiationDependent()) |
| 161 | return true; |
| 162 | } |
| 163 | |
| 164 | return false; |
| 165 | } |
David Blaikie | 3026348 | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 166 | |
| 167 | llvm_unreachable("Invalid TemplateArgument Kind!"); |
Douglas Gregor | 561f812 | 2011-07-01 01:22:09 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 170 | bool TemplateArgument::isPackExpansion() const { |
| 171 | switch (getKind()) { |
| 172 | case Null: |
| 173 | case Declaration: |
| 174 | case Integral: |
| 175 | case Pack: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 176 | case Template: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 177 | case NullPtr: |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 178 | return false; |
| 179 | |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 180 | case TemplateExpansion: |
| 181 | return true; |
| 182 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 183 | case Type: |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 184 | return isa<PackExpansionType>(getAsType()); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 185 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 186 | case Expression: |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 187 | return isa<PackExpansionExpr>(getAsExpr()); |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 188 | } |
David Blaikie | 3026348 | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 189 | |
| 190 | llvm_unreachable("Invalid TemplateArgument Kind!"); |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 191 | } |
| 192 | |
Douglas Gregor | d093722 | 2010-12-13 22:49:22 +0000 | [diff] [blame] | 193 | bool TemplateArgument::containsUnexpandedParameterPack() const { |
| 194 | switch (getKind()) { |
| 195 | case Null: |
| 196 | case Declaration: |
| 197 | case Integral: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 198 | case TemplateExpansion: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 199 | case NullPtr: |
Douglas Gregor | d093722 | 2010-12-13 22:49:22 +0000 | [diff] [blame] | 200 | break; |
| 201 | |
| 202 | case Type: |
| 203 | if (getAsType()->containsUnexpandedParameterPack()) |
| 204 | return true; |
| 205 | break; |
| 206 | |
| 207 | case Template: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 208 | if (getAsTemplate().containsUnexpandedParameterPack()) |
Douglas Gregor | d093722 | 2010-12-13 22:49:22 +0000 | [diff] [blame] | 209 | return true; |
| 210 | break; |
| 211 | |
| 212 | case Expression: |
| 213 | if (getAsExpr()->containsUnexpandedParameterPack()) |
| 214 | return true; |
| 215 | break; |
| 216 | |
| 217 | case Pack: |
| 218 | for (pack_iterator P = pack_begin(), PEnd = pack_end(); P != PEnd; ++P) |
| 219 | if (P->containsUnexpandedParameterPack()) |
| 220 | return true; |
| 221 | |
| 222 | break; |
| 223 | } |
| 224 | |
| 225 | return false; |
| 226 | } |
| 227 | |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 228 | llvm::Optional<unsigned> TemplateArgument::getNumTemplateExpansions() const { |
| 229 | assert(Kind == TemplateExpansion); |
| 230 | if (TemplateArg.NumExpansions) |
| 231 | return TemplateArg.NumExpansions - 1; |
| 232 | |
| 233 | return llvm::Optional<unsigned>(); |
| 234 | } |
| 235 | |
John McCall | 275c10a | 2009-10-29 07:48:15 +0000 | [diff] [blame] | 236 | void TemplateArgument::Profile(llvm::FoldingSetNodeID &ID, |
Jay Foad | 4ba2a17 | 2011-01-12 09:06:06 +0000 | [diff] [blame] | 237 | const ASTContext &Context) const { |
John McCall | 275c10a | 2009-10-29 07:48:15 +0000 | [diff] [blame] | 238 | ID.AddInteger(Kind); |
| 239 | switch (Kind) { |
| 240 | case Null: |
| 241 | break; |
| 242 | |
| 243 | case Type: |
| 244 | getAsType().Profile(ID); |
| 245 | break; |
| 246 | |
| 247 | case Declaration: |
| 248 | ID.AddPointer(getAsDecl()? getAsDecl()->getCanonicalDecl() : 0); |
| 249 | break; |
| 250 | |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 251 | case Template: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 252 | case TemplateExpansion: { |
| 253 | TemplateName Template = getAsTemplateOrTemplatePattern(); |
Douglas Gregor | 74295b3 | 2009-11-23 12:52:47 +0000 | [diff] [blame] | 254 | if (TemplateTemplateParmDecl *TTP |
| 255 | = dyn_cast_or_null<TemplateTemplateParmDecl>( |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 256 | Template.getAsTemplateDecl())) { |
Douglas Gregor | 74295b3 | 2009-11-23 12:52:47 +0000 | [diff] [blame] | 257 | ID.AddBoolean(true); |
| 258 | ID.AddInteger(TTP->getDepth()); |
| 259 | ID.AddInteger(TTP->getPosition()); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 260 | ID.AddBoolean(TTP->isParameterPack()); |
Douglas Gregor | 74295b3 | 2009-11-23 12:52:47 +0000 | [diff] [blame] | 261 | } else { |
| 262 | ID.AddBoolean(false); |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 263 | ID.AddPointer(Context.getCanonicalTemplateName(Template) |
| 264 | .getAsVoidPointer()); |
Douglas Gregor | 74295b3 | 2009-11-23 12:52:47 +0000 | [diff] [blame] | 265 | } |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 266 | break; |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 267 | } |
Douglas Gregor | 788cd06 | 2009-11-11 01:00:40 +0000 | [diff] [blame] | 268 | |
John McCall | 275c10a | 2009-10-29 07:48:15 +0000 | [diff] [blame] | 269 | case Integral: |
Benjamin Kramer | 8552437 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 270 | getAsIntegral().Profile(ID); |
John McCall | 275c10a | 2009-10-29 07:48:15 +0000 | [diff] [blame] | 271 | getIntegralType().Profile(ID); |
| 272 | break; |
| 273 | |
| 274 | case Expression: |
| 275 | getAsExpr()->Profile(ID, Context, true); |
| 276 | break; |
| 277 | |
| 278 | case Pack: |
| 279 | ID.AddInteger(Args.NumArgs); |
| 280 | for (unsigned I = 0; I != Args.NumArgs; ++I) |
| 281 | Args.Args[I].Profile(ID, Context); |
| 282 | } |
| 283 | } |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 284 | |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 285 | bool TemplateArgument::structurallyEquals(const TemplateArgument &Other) const { |
| 286 | if (getKind() != Other.getKind()) return false; |
| 287 | |
| 288 | switch (getKind()) { |
| 289 | case Null: |
| 290 | case Type: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 291 | case Expression: |
| 292 | case Template: |
| 293 | case TemplateExpansion: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 294 | case NullPtr: |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 295 | return TypeOrValue == Other.TypeOrValue; |
| 296 | |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 297 | case Declaration: |
| 298 | return getAsDecl() == Other.getAsDecl() && |
| 299 | isDeclForReferenceParam() && Other.isDeclForReferenceParam(); |
| 300 | |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 301 | case Integral: |
| 302 | return getIntegralType() == Other.getIntegralType() && |
Benjamin Kramer | 8552437 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 303 | getAsIntegral() == Other.getAsIntegral(); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 304 | |
| 305 | case Pack: |
| 306 | if (Args.NumArgs != Other.Args.NumArgs) return false; |
| 307 | for (unsigned I = 0, E = Args.NumArgs; I != E; ++I) |
| 308 | if (!Args.Args[I].structurallyEquals(Other.Args.Args[I])) |
| 309 | return false; |
| 310 | return true; |
| 311 | } |
| 312 | |
David Blaikie | 3026348 | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 313 | llvm_unreachable("Invalid TemplateArgument Kind!"); |
John McCall | 3350095 | 2010-06-11 00:33:02 +0000 | [diff] [blame] | 314 | } |
| 315 | |
Douglas Gregor | e02e262 | 2010-12-22 21:19:48 +0000 | [diff] [blame] | 316 | TemplateArgument TemplateArgument::getPackExpansionPattern() const { |
| 317 | assert(isPackExpansion()); |
| 318 | |
| 319 | switch (getKind()) { |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 320 | case Type: |
| 321 | return getAsType()->getAs<PackExpansionType>()->getPattern(); |
| 322 | |
| 323 | case Expression: |
| 324 | return cast<PackExpansionExpr>(getAsExpr())->getPattern(); |
| 325 | |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 326 | case TemplateExpansion: |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 327 | return TemplateArgument(getAsTemplateOrTemplatePattern()); |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 328 | |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 329 | case Declaration: |
| 330 | case Integral: |
| 331 | case Pack: |
| 332 | case Null: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 333 | case Template: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 334 | case NullPtr: |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 335 | return TemplateArgument(); |
Douglas Gregor | e02e262 | 2010-12-22 21:19:48 +0000 | [diff] [blame] | 336 | } |
David Blaikie | 3026348 | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 337 | |
| 338 | llvm_unreachable("Invalid TemplateArgument Kind!"); |
Douglas Gregor | e02e262 | 2010-12-22 21:19:48 +0000 | [diff] [blame] | 339 | } |
| 340 | |
Douglas Gregor | 87dd697 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 341 | void TemplateArgument::print(const PrintingPolicy &Policy, |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 342 | raw_ostream &Out) const { |
Douglas Gregor | 87dd697 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 343 | switch (getKind()) { |
| 344 | case Null: |
| 345 | Out << "<no value>"; |
| 346 | break; |
| 347 | |
| 348 | case Type: { |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 349 | PrintingPolicy SubPolicy(Policy); |
| 350 | SubPolicy.SuppressStrongLifetime = true; |
Douglas Gregor | 87dd697 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 351 | std::string TypeStr; |
Douglas Gregor | e559ca1 | 2011-06-17 22:11:49 +0000 | [diff] [blame] | 352 | getAsType().getAsStringInternal(TypeStr, SubPolicy); |
Douglas Gregor | 87dd697 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 353 | Out << TypeStr; |
| 354 | break; |
| 355 | } |
| 356 | |
| 357 | case Declaration: { |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 358 | NamedDecl *ND = cast<NamedDecl>(getAsDecl()); |
| 359 | if (ND->getDeclName()) { |
| 360 | // FIXME: distinguish between pointer and reference args? |
| 361 | Out << *ND; |
Douglas Gregor | d2008e2 | 2012-04-06 22:40:38 +0000 | [diff] [blame] | 362 | } else { |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 363 | Out << "<anonymous>"; |
Douglas Gregor | 87dd697 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 364 | } |
| 365 | break; |
| 366 | } |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 367 | |
Abramo Bagnara | abd5fa2 | 2012-10-05 04:43:29 +0000 | [diff] [blame] | 368 | case NullPtr: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 369 | Out << "nullptr"; |
Abramo Bagnara | abd5fa2 | 2012-10-05 04:43:29 +0000 | [diff] [blame] | 370 | break; |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 371 | |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 372 | case Template: |
Douglas Gregor | 87dd697 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 373 | getAsTemplate().print(Out, Policy); |
| 374 | break; |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 375 | |
| 376 | case TemplateExpansion: |
| 377 | getAsTemplateOrTemplatePattern().print(Out, Policy); |
| 378 | Out << "..."; |
| 379 | break; |
| 380 | |
Douglas Gregor | 87dd697 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 381 | case Integral: { |
Chandler Carruth | 781701c | 2011-02-19 00:21:00 +0000 | [diff] [blame] | 382 | printIntegral(*this, Out); |
Douglas Gregor | 87dd697 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 383 | break; |
| 384 | } |
| 385 | |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 386 | case Expression: |
Douglas Gregor | 87dd697 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 387 | getAsExpr()->printPretty(Out, 0, Policy); |
| 388 | break; |
Douglas Gregor | 87dd697 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 389 | |
| 390 | case Pack: |
| 391 | Out << "<"; |
| 392 | bool First = true; |
| 393 | for (TemplateArgument::pack_iterator P = pack_begin(), PEnd = pack_end(); |
| 394 | P != PEnd; ++P) { |
| 395 | if (First) |
| 396 | First = false; |
| 397 | else |
| 398 | Out << ", "; |
| 399 | |
| 400 | P->print(Policy, Out); |
| 401 | } |
| 402 | Out << ">"; |
| 403 | break; |
| 404 | } |
| 405 | } |
| 406 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 407 | //===----------------------------------------------------------------------===// |
| 408 | // TemplateArgumentLoc Implementation |
| 409 | //===----------------------------------------------------------------------===// |
| 410 | |
Douglas Gregor | b0ddf3a | 2011-01-06 00:33:28 +0000 | [diff] [blame] | 411 | TemplateArgumentLocInfo::TemplateArgumentLocInfo() { |
Chandler Carruth | 75c4064 | 2011-04-28 08:19:45 +0000 | [diff] [blame] | 412 | memset((void*)this, 0, sizeof(TemplateArgumentLocInfo)); |
Douglas Gregor | b0ddf3a | 2011-01-06 00:33:28 +0000 | [diff] [blame] | 413 | } |
| 414 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 415 | SourceRange TemplateArgumentLoc::getSourceRange() const { |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 416 | switch (Argument.getKind()) { |
| 417 | case TemplateArgument::Expression: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 418 | return getSourceExpression()->getSourceRange(); |
Zhanyong Wan | f38ef0c | 2010-09-03 23:50:56 +0000 | [diff] [blame] | 419 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 420 | case TemplateArgument::Declaration: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 421 | return getSourceDeclExpression()->getSourceRange(); |
Zhanyong Wan | f38ef0c | 2010-09-03 23:50:56 +0000 | [diff] [blame] | 422 | |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 423 | case TemplateArgument::NullPtr: |
| 424 | return getSourceNullPtrExpression()->getSourceRange(); |
| 425 | |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 426 | case TemplateArgument::Type: |
Zhanyong Wan | f38ef0c | 2010-09-03 23:50:56 +0000 | [diff] [blame] | 427 | if (TypeSourceInfo *TSI = getTypeSourceInfo()) |
| 428 | return TSI->getTypeLoc().getSourceRange(); |
| 429 | else |
| 430 | return SourceRange(); |
| 431 | |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 432 | case TemplateArgument::Template: |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 433 | if (getTemplateQualifierLoc()) |
| 434 | return SourceRange(getTemplateQualifierLoc().getBeginLoc(), |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 435 | getTemplateNameLoc()); |
| 436 | return SourceRange(getTemplateNameLoc()); |
| 437 | |
| 438 | case TemplateArgument::TemplateExpansion: |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 439 | if (getTemplateQualifierLoc()) |
| 440 | return SourceRange(getTemplateQualifierLoc().getBeginLoc(), |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 441 | getTemplateEllipsisLoc()); |
| 442 | return SourceRange(getTemplateNameLoc(), getTemplateEllipsisLoc()); |
| 443 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 444 | case TemplateArgument::Integral: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 445 | return getSourceIntegralExpression()->getSourceRange(); |
| 446 | |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 447 | case TemplateArgument::Pack: |
| 448 | case TemplateArgument::Null: |
John McCall | 828bff2 | 2009-10-29 18:45:58 +0000 | [diff] [blame] | 449 | return SourceRange(); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 450 | } |
| 451 | |
David Blaikie | 3026348 | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 452 | llvm_unreachable("Invalid TemplateArgument Kind!"); |
John McCall | 833ca99 | 2009-10-29 08:12:44 +0000 | [diff] [blame] | 453 | } |
Douglas Gregor | a933319 | 2010-05-08 17:41:32 +0000 | [diff] [blame] | 454 | |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 455 | TemplateArgumentLoc |
| 456 | TemplateArgumentLoc::getPackExpansionPattern(SourceLocation &Ellipsis, |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 457 | llvm::Optional<unsigned> &NumExpansions, |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 458 | ASTContext &Context) const { |
| 459 | assert(Argument.isPackExpansion()); |
| 460 | |
| 461 | switch (Argument.getKind()) { |
| 462 | case TemplateArgument::Type: { |
Douglas Gregor | 03491de | 2010-12-21 22:10:26 +0000 | [diff] [blame] | 463 | // FIXME: We shouldn't ever have to worry about missing |
| 464 | // type-source info! |
| 465 | TypeSourceInfo *ExpansionTSInfo = getTypeSourceInfo(); |
| 466 | if (!ExpansionTSInfo) |
| 467 | ExpansionTSInfo = Context.getTrivialTypeSourceInfo( |
| 468 | getArgument().getAsType(), |
| 469 | Ellipsis); |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 470 | PackExpansionTypeLoc Expansion |
Douglas Gregor | 03491de | 2010-12-21 22:10:26 +0000 | [diff] [blame] | 471 | = cast<PackExpansionTypeLoc>(ExpansionTSInfo->getTypeLoc()); |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 472 | Ellipsis = Expansion.getEllipsisLoc(); |
| 473 | |
| 474 | TypeLoc Pattern = Expansion.getPatternLoc(); |
Douglas Gregor | cded4f6 | 2011-01-14 17:04:44 +0000 | [diff] [blame] | 475 | NumExpansions = Expansion.getTypePtr()->getNumExpansions(); |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 476 | |
| 477 | // FIXME: This is horrible. We know where the source location data is for |
| 478 | // the pattern, and we have the pattern's type, but we are forced to copy |
| 479 | // them into an ASTContext because TypeSourceInfo bundles them together |
| 480 | // and TemplateArgumentLoc traffics in TypeSourceInfo pointers. |
| 481 | TypeSourceInfo *PatternTSInfo |
| 482 | = Context.CreateTypeSourceInfo(Pattern.getType(), |
| 483 | Pattern.getFullDataSize()); |
| 484 | memcpy(PatternTSInfo->getTypeLoc().getOpaqueData(), |
| 485 | Pattern.getOpaqueData(), Pattern.getFullDataSize()); |
| 486 | return TemplateArgumentLoc(TemplateArgument(Pattern.getType()), |
| 487 | PatternTSInfo); |
| 488 | } |
| 489 | |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 490 | case TemplateArgument::Expression: { |
Douglas Gregor | b0ddf3a | 2011-01-06 00:33:28 +0000 | [diff] [blame] | 491 | PackExpansionExpr *Expansion |
| 492 | = cast<PackExpansionExpr>(Argument.getAsExpr()); |
| 493 | Expr *Pattern = Expansion->getPattern(); |
| 494 | Ellipsis = Expansion->getEllipsisLoc(); |
Douglas Gregor | 67fd125 | 2011-01-14 21:20:45 +0000 | [diff] [blame] | 495 | NumExpansions = Expansion->getNumExpansions(); |
Douglas Gregor | be230c3 | 2011-01-03 17:17:50 +0000 | [diff] [blame] | 496 | return TemplateArgumentLoc(Pattern, Pattern); |
| 497 | } |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 498 | |
| 499 | case TemplateArgument::TemplateExpansion: |
Douglas Gregor | b0ddf3a | 2011-01-06 00:33:28 +0000 | [diff] [blame] | 500 | Ellipsis = getTemplateEllipsisLoc(); |
Douglas Gregor | 2be29f4 | 2011-01-14 23:41:42 +0000 | [diff] [blame] | 501 | NumExpansions = Argument.getNumTemplateExpansions(); |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 502 | return TemplateArgumentLoc(Argument.getPackExpansionPattern(), |
Douglas Gregor | b6744ef | 2011-03-02 17:09:35 +0000 | [diff] [blame] | 503 | getTemplateQualifierLoc(), |
Douglas Gregor | ba68eca | 2011-01-05 17:40:24 +0000 | [diff] [blame] | 504 | getTemplateNameLoc()); |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 505 | |
| 506 | case TemplateArgument::Declaration: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 507 | case TemplateArgument::NullPtr: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 508 | case TemplateArgument::Template: |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 509 | case TemplateArgument::Integral: |
| 510 | case TemplateArgument::Pack: |
| 511 | case TemplateArgument::Null: |
| 512 | return TemplateArgumentLoc(); |
| 513 | } |
David Blaikie | 3026348 | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 514 | |
| 515 | llvm_unreachable("Invalid TemplateArgument Kind!"); |
Douglas Gregor | 8491ffe | 2010-12-20 22:05:00 +0000 | [diff] [blame] | 516 | } |
| 517 | |
Douglas Gregor | a933319 | 2010-05-08 17:41:32 +0000 | [diff] [blame] | 518 | const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB, |
| 519 | const TemplateArgument &Arg) { |
| 520 | switch (Arg.getKind()) { |
| 521 | case TemplateArgument::Null: |
John McCall | 67c4a0c | 2010-08-05 04:58:04 +0000 | [diff] [blame] | 522 | // This is bad, but not as bad as crashing because of argument |
| 523 | // count mismatches. |
| 524 | return DB << "(null template argument)"; |
Douglas Gregor | a933319 | 2010-05-08 17:41:32 +0000 | [diff] [blame] | 525 | |
| 526 | case TemplateArgument::Type: |
| 527 | return DB << Arg.getAsType(); |
| 528 | |
| 529 | case TemplateArgument::Declaration: |
Eli Friedman | d7a6b16 | 2012-09-26 02:36:12 +0000 | [diff] [blame] | 530 | return DB << Arg.getAsDecl(); |
| 531 | |
| 532 | case TemplateArgument::NullPtr: |
Douglas Gregor | d2008e2 | 2012-04-06 22:40:38 +0000 | [diff] [blame] | 533 | return DB << "nullptr"; |
Douglas Gregor | a933319 | 2010-05-08 17:41:32 +0000 | [diff] [blame] | 534 | |
| 535 | case TemplateArgument::Integral: |
Benjamin Kramer | 8552437 | 2012-06-07 15:09:51 +0000 | [diff] [blame] | 536 | return DB << Arg.getAsIntegral().toString(10); |
Douglas Gregor | a933319 | 2010-05-08 17:41:32 +0000 | [diff] [blame] | 537 | |
| 538 | case TemplateArgument::Template: |
Douglas Gregor | a7fc901 | 2011-01-05 18:58:31 +0000 | [diff] [blame] | 539 | return DB << Arg.getAsTemplate(); |
| 540 | |
| 541 | case TemplateArgument::TemplateExpansion: |
| 542 | return DB << Arg.getAsTemplateOrTemplatePattern() << "..."; |
| 543 | |
Douglas Gregor | a933319 | 2010-05-08 17:41:32 +0000 | [diff] [blame] | 544 | case TemplateArgument::Expression: { |
| 545 | // This shouldn't actually ever happen, so it's okay that we're |
| 546 | // regurgitating an expression here. |
| 547 | // FIXME: We're guessing at LangOptions! |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 548 | SmallString<32> Str; |
Douglas Gregor | a933319 | 2010-05-08 17:41:32 +0000 | [diff] [blame] | 549 | llvm::raw_svector_ostream OS(Str); |
| 550 | LangOptions LangOpts; |
| 551 | LangOpts.CPlusPlus = true; |
| 552 | PrintingPolicy Policy(LangOpts); |
| 553 | Arg.getAsExpr()->printPretty(OS, 0, Policy); |
| 554 | return DB << OS.str(); |
| 555 | } |
| 556 | |
Douglas Gregor | 87dd697 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 557 | case TemplateArgument::Pack: { |
| 558 | // FIXME: We're guessing at LangOptions! |
Dylan Noblesmith | f7ccbad | 2012-02-05 02:13:05 +0000 | [diff] [blame] | 559 | SmallString<32> Str; |
Douglas Gregor | 87dd697 | 2010-12-20 16:52:59 +0000 | [diff] [blame] | 560 | llvm::raw_svector_ostream OS(Str); |
| 561 | LangOptions LangOpts; |
| 562 | LangOpts.CPlusPlus = true; |
| 563 | PrintingPolicy Policy(LangOpts); |
| 564 | Arg.print(Policy, OS); |
| 565 | return DB << OS.str(); |
| 566 | } |
Douglas Gregor | a933319 | 2010-05-08 17:41:32 +0000 | [diff] [blame] | 567 | } |
David Blaikie | 3026348 | 2012-01-20 21:50:17 +0000 | [diff] [blame] | 568 | |
| 569 | llvm_unreachable("Invalid TemplateArgument Kind!"); |
Douglas Gregor | a933319 | 2010-05-08 17:41:32 +0000 | [diff] [blame] | 570 | } |
Argyrios Kyrtzidis | 71a7605 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 571 | |
| 572 | const ASTTemplateArgumentListInfo * |
| 573 | ASTTemplateArgumentListInfo::Create(ASTContext &C, |
| 574 | const TemplateArgumentListInfo &List) { |
Richard Smith | 97f6026 | 2012-08-15 01:22:58 +0000 | [diff] [blame] | 575 | std::size_t size = ASTTemplateArgumentListInfo::sizeFor(List.size()); |
Argyrios Kyrtzidis | 71a7605 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 576 | void *Mem = C.Allocate(size, llvm::alignOf<ASTTemplateArgumentListInfo>()); |
| 577 | ASTTemplateArgumentListInfo *TAI = new (Mem) ASTTemplateArgumentListInfo(); |
| 578 | TAI->initializeFrom(List); |
| 579 | return TAI; |
| 580 | } |
| 581 | |
| 582 | void ASTTemplateArgumentListInfo::initializeFrom( |
| 583 | const TemplateArgumentListInfo &Info) { |
| 584 | LAngleLoc = Info.getLAngleLoc(); |
| 585 | RAngleLoc = Info.getRAngleLoc(); |
| 586 | NumTemplateArgs = Info.size(); |
| 587 | |
| 588 | TemplateArgumentLoc *ArgBuffer = getTemplateArgs(); |
| 589 | for (unsigned i = 0; i != NumTemplateArgs; ++i) |
| 590 | new (&ArgBuffer[i]) TemplateArgumentLoc(Info[i]); |
| 591 | } |
| 592 | |
| 593 | void ASTTemplateArgumentListInfo::initializeFrom( |
| 594 | const TemplateArgumentListInfo &Info, |
| 595 | bool &Dependent, |
| 596 | bool &InstantiationDependent, |
| 597 | bool &ContainsUnexpandedParameterPack) { |
| 598 | LAngleLoc = Info.getLAngleLoc(); |
| 599 | RAngleLoc = Info.getRAngleLoc(); |
| 600 | NumTemplateArgs = Info.size(); |
| 601 | |
| 602 | TemplateArgumentLoc *ArgBuffer = getTemplateArgs(); |
| 603 | for (unsigned i = 0; i != NumTemplateArgs; ++i) { |
| 604 | Dependent = Dependent || Info[i].getArgument().isDependent(); |
| 605 | InstantiationDependent = InstantiationDependent || |
| 606 | Info[i].getArgument().isInstantiationDependent(); |
| 607 | ContainsUnexpandedParameterPack |
| 608 | = ContainsUnexpandedParameterPack || |
| 609 | Info[i].getArgument().containsUnexpandedParameterPack(); |
| 610 | |
| 611 | new (&ArgBuffer[i]) TemplateArgumentLoc(Info[i]); |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | void ASTTemplateArgumentListInfo::copyInto( |
| 616 | TemplateArgumentListInfo &Info) const { |
| 617 | Info.setLAngleLoc(LAngleLoc); |
| 618 | Info.setRAngleLoc(RAngleLoc); |
| 619 | for (unsigned I = 0; I != NumTemplateArgs; ++I) |
| 620 | Info.addArgument(getTemplateArgs()[I]); |
| 621 | } |
| 622 | |
| 623 | std::size_t ASTTemplateArgumentListInfo::sizeFor(unsigned NumTemplateArgs) { |
| 624 | return sizeof(ASTTemplateArgumentListInfo) + |
| 625 | sizeof(TemplateArgumentLoc) * NumTemplateArgs; |
| 626 | } |
| 627 | |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 628 | void |
| 629 | ASTTemplateKWAndArgsInfo::initializeFrom(SourceLocation TemplateKWLoc, |
| 630 | const TemplateArgumentListInfo &Info) { |
| 631 | Base::initializeFrom(Info); |
| 632 | setTemplateKeywordLoc(TemplateKWLoc); |
Argyrios Kyrtzidis | 71a7605 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 633 | } |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 634 | |
| 635 | void |
| 636 | ASTTemplateKWAndArgsInfo |
| 637 | ::initializeFrom(SourceLocation TemplateKWLoc, |
| 638 | const TemplateArgumentListInfo &Info, |
| 639 | bool &Dependent, |
| 640 | bool &InstantiationDependent, |
| 641 | bool &ContainsUnexpandedParameterPack) { |
| 642 | Base::initializeFrom(Info, Dependent, InstantiationDependent, |
| 643 | ContainsUnexpandedParameterPack); |
| 644 | setTemplateKeywordLoc(TemplateKWLoc); |
| 645 | } |
| 646 | |
| 647 | void |
| 648 | ASTTemplateKWAndArgsInfo::initializeFrom(SourceLocation TemplateKWLoc) { |
| 649 | // No explicit template arguments, but template keyword loc is valid. |
| 650 | assert(TemplateKWLoc.isValid()); |
| 651 | LAngleLoc = SourceLocation(); |
| 652 | RAngleLoc = SourceLocation(); |
| 653 | NumTemplateArgs = 0; |
| 654 | setTemplateKeywordLoc(TemplateKWLoc); |
| 655 | } |
| 656 | |
| 657 | std::size_t |
| 658 | ASTTemplateKWAndArgsInfo::sizeFor(unsigned NumTemplateArgs) { |
| 659 | // Add space for the template keyword location. |
Richard Smith | 97f6026 | 2012-08-15 01:22:58 +0000 | [diff] [blame] | 660 | // FIXME: There's room for this in the padding before the template args in |
| 661 | // 64-bit builds. |
Abramo Bagnara | e4b9276 | 2012-01-27 09:46:47 +0000 | [diff] [blame] | 662 | return Base::sizeFor(NumTemplateArgs) + sizeof(SourceLocation); |
| 663 | } |