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