blob: 7ed2ce851b4cef0534e8bd0a1bc32d8dbf03183a [file] [log] [blame]
Sebastian Redl06a59bb2009-10-23 22:13:42 +00001//===--- DeclTemplate.cpp - Template Declaration AST Node Implementation --===//
Douglas Gregoraaba5e32009-02-04 19:02:06 +00002//
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 the C++ related Decl classes for templates.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/AST/DeclCXX.h"
15#include "clang/AST/DeclTemplate.h"
Douglas Gregor55f6b142009-02-09 18:46:07 +000016#include "clang/AST/Expr.h"
Douglas Gregorb95cc972011-01-04 02:33:52 +000017#include "clang/AST/ExprCXX.h"
Douglas Gregoraaba5e32009-02-04 19:02:06 +000018#include "clang/AST/ASTContext.h"
John McCall833ca992009-10-29 08:12:44 +000019#include "clang/AST/TypeLoc.h"
Argyrios Kyrtzidisbef1a7b2010-10-28 07:38:42 +000020#include "clang/AST/ASTMutationListener.h"
Douglas Gregoraaba5e32009-02-04 19:02:06 +000021#include "clang/Basic/IdentifierTable.h"
22#include "llvm/ADT/STLExtras.h"
Douglas Gregor910f8002010-11-07 23:05:16 +000023#include <memory>
Douglas Gregoraaba5e32009-02-04 19:02:06 +000024using namespace clang;
25
26//===----------------------------------------------------------------------===//
27// TemplateParameterList Implementation
28//===----------------------------------------------------------------------===//
29
Douglas Gregorddc29e12009-02-06 22:42:48 +000030TemplateParameterList::TemplateParameterList(SourceLocation TemplateLoc,
31 SourceLocation LAngleLoc,
Douglas Gregorbf4ea562009-09-15 16:23:51 +000032 NamedDecl **Params, unsigned NumParams,
Douglas Gregorddc29e12009-02-06 22:42:48 +000033 SourceLocation RAngleLoc)
34 : TemplateLoc(TemplateLoc), LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc),
35 NumParams(NumParams) {
Douglas Gregoraaba5e32009-02-04 19:02:06 +000036 for (unsigned Idx = 0; Idx < NumParams; ++Idx)
37 begin()[Idx] = Params[Idx];
38}
39
40TemplateParameterList *
Jay Foad4ba2a172011-01-12 09:06:06 +000041TemplateParameterList::Create(const ASTContext &C, SourceLocation TemplateLoc,
Douglas Gregorbf4ea562009-09-15 16:23:51 +000042 SourceLocation LAngleLoc, NamedDecl **Params,
Douglas Gregorddc29e12009-02-06 22:42:48 +000043 unsigned NumParams, SourceLocation RAngleLoc) {
Douglas Gregorbf4ea562009-09-15 16:23:51 +000044 unsigned Size = sizeof(TemplateParameterList)
45 + sizeof(NamedDecl *) * NumParams;
Douglas Gregoraaba5e32009-02-04 19:02:06 +000046 unsigned Align = llvm::AlignOf<TemplateParameterList>::Alignment;
47 void *Mem = C.Allocate(Size, Align);
Mike Stump1eb44332009-09-09 15:08:12 +000048 return new (Mem) TemplateParameterList(TemplateLoc, LAngleLoc, Params,
Douglas Gregorddc29e12009-02-06 22:42:48 +000049 NumParams, RAngleLoc);
Douglas Gregoraaba5e32009-02-04 19:02:06 +000050}
51
Douglas Gregor62cb18d2009-02-11 18:16:40 +000052unsigned TemplateParameterList::getMinRequiredArguments() const {
Douglas Gregor6952f1e2011-01-19 20:10:05 +000053 unsigned NumRequiredArgs = 0;
54 for (iterator P = const_cast<TemplateParameterList *>(this)->begin(),
55 PEnd = const_cast<TemplateParameterList *>(this)->end();
56 P != PEnd; ++P) {
57 if ((*P)->isTemplateParameterPack()) {
58 if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*P))
59 if (NTTP->isExpandedParameterPack()) {
60 NumRequiredArgs += NTTP->getNumExpansionTypes();
61 continue;
62 }
63
Douglas Gregor62cb18d2009-02-11 18:16:40 +000064 break;
Douglas Gregor6952f1e2011-01-19 20:10:05 +000065 }
66
67 if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*P)) {
68 if (TTP->hasDefaultArgument())
69 break;
70 } else if (NonTypeTemplateParmDecl *NTTP
71 = dyn_cast<NonTypeTemplateParmDecl>(*P)) {
72 if (NTTP->hasDefaultArgument())
73 break;
74 } else if (cast<TemplateTemplateParmDecl>(*P)->hasDefaultArgument())
75 break;
76
77 ++NumRequiredArgs;
Douglas Gregor62cb18d2009-02-11 18:16:40 +000078 }
Douglas Gregor6952f1e2011-01-19 20:10:05 +000079
Douglas Gregor62cb18d2009-02-11 18:16:40 +000080 return NumRequiredArgs;
81}
82
Douglas Gregored9c0f92009-10-29 00:04:11 +000083unsigned TemplateParameterList::getDepth() const {
84 if (size() == 0)
85 return 0;
86
87 const NamedDecl *FirstParm = getParam(0);
88 if (const TemplateTypeParmDecl *TTP
89 = dyn_cast<TemplateTypeParmDecl>(FirstParm))
90 return TTP->getDepth();
91 else if (const NonTypeTemplateParmDecl *NTTP
92 = dyn_cast<NonTypeTemplateParmDecl>(FirstParm))
93 return NTTP->getDepth();
94 else
95 return cast<TemplateTemplateParmDecl>(FirstParm)->getDepth();
96}
97
Douglas Gregor787a40d2011-03-04 18:32:38 +000098static void AdoptTemplateParameterList(TemplateParameterList *Params,
99 DeclContext *Owner) {
100 for (TemplateParameterList::iterator P = Params->begin(),
101 PEnd = Params->end();
102 P != PEnd; ++P) {
103 (*P)->setDeclContext(Owner);
104
105 if (TemplateTemplateParmDecl *TTP = dyn_cast<TemplateTemplateParmDecl>(*P))
106 AdoptTemplateParameterList(TTP->getTemplateParameters(), Owner);
107 }
108}
109
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000110//===----------------------------------------------------------------------===//
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000111// RedeclarableTemplateDecl Implementation
112//===----------------------------------------------------------------------===//
113
114RedeclarableTemplateDecl::CommonBase *RedeclarableTemplateDecl::getCommonPtr() {
115 // Find the first declaration of this function template.
116 RedeclarableTemplateDecl *First = getCanonicalDecl();
117
118 if (First->CommonOrPrev.isNull()) {
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000119 CommonBase *CommonPtr = First->newCommon(getASTContext());
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000120 First->CommonOrPrev = CommonPtr;
Peter Collingbourne8a798a72010-07-29 16:12:01 +0000121 CommonPtr->Latest = First;
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000122 }
123 return First->CommonOrPrev.get<CommonBase*>();
124}
125
126
127RedeclarableTemplateDecl *RedeclarableTemplateDecl::getCanonicalDeclImpl() {
128 RedeclarableTemplateDecl *Tmpl = this;
129 while (Tmpl->getPreviousDeclaration())
130 Tmpl = Tmpl->getPreviousDeclaration();
131 return Tmpl;
132}
133
Peter Collingbourne8a798a72010-07-29 16:12:01 +0000134void RedeclarableTemplateDecl::setPreviousDeclarationImpl(
135 RedeclarableTemplateDecl *Prev) {
136 if (Prev) {
137 CommonBase *Common = Prev->getCommonPtr();
138 Prev = Common->Latest;
139 Common->Latest = this;
140 CommonOrPrev = Prev;
141 } else {
142 assert(CommonOrPrev.is<CommonBase*>() && "Cannot reset TemplateDecl Prev");
143 }
144}
145
Peter Collingbournef88718e2010-07-29 16:12:09 +0000146RedeclarableTemplateDecl *RedeclarableTemplateDecl::getNextRedeclaration() {
147 if (CommonOrPrev.is<RedeclarableTemplateDecl*>())
148 return CommonOrPrev.get<RedeclarableTemplateDecl*>();
149 CommonBase *Common = CommonOrPrev.get<CommonBase*>();
150 return Common ? Common->Latest : this;
151}
152
Peter Collingbourne40485902010-07-30 17:09:04 +0000153template <class EntryType>
154typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType*
155RedeclarableTemplateDecl::findSpecializationImpl(
156 llvm::FoldingSet<EntryType> &Specs,
157 const TemplateArgument *Args, unsigned NumArgs,
158 void *&InsertPos) {
159 typedef SpecEntryTraits<EntryType> SETraits;
160 llvm::FoldingSetNodeID ID;
161 EntryType::Profile(ID,Args,NumArgs, getASTContext());
162 EntryType *Entry = Specs.FindNodeOrInsertPos(ID, InsertPos);
163 return Entry ? SETraits::getMostRecentDeclaration(Entry) : 0;
164}
165
Douglas Gregorc494f772011-03-05 17:54:25 +0000166/// \brief Generate the injected template arguments for the given template
167/// parameter list, e.g., for the injected-class-name of a class template.
168static void GenerateInjectedTemplateArgs(ASTContext &Context,
169 TemplateParameterList *Params,
170 TemplateArgument *Args) {
171 for (TemplateParameterList::iterator Param = Params->begin(),
172 ParamEnd = Params->end();
173 Param != ParamEnd; ++Param) {
174 TemplateArgument Arg;
175 if (TemplateTypeParmDecl *TTP = dyn_cast<TemplateTypeParmDecl>(*Param)) {
176 QualType ArgType = Context.getTypeDeclType(TTP);
177 if (TTP->isParameterPack())
178 ArgType = Context.getPackExpansionType(ArgType,
179 llvm::Optional<unsigned>());
180
181 Arg = TemplateArgument(ArgType);
182 } else if (NonTypeTemplateParmDecl *NTTP =
183 dyn_cast<NonTypeTemplateParmDecl>(*Param)) {
184 Expr *E = new (Context) DeclRefExpr(NTTP,
185 NTTP->getType().getNonLValueExprType(Context),
186 Expr::getValueKindForType(NTTP->getType()),
187 NTTP->getLocation());
188
189 if (NTTP->isParameterPack())
190 E = new (Context) PackExpansionExpr(Context.DependentTy, E,
191 NTTP->getLocation(),
192 llvm::Optional<unsigned>());
193 Arg = TemplateArgument(E);
194 } else {
195 TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*Param);
196 if (TTP->isParameterPack())
197 Arg = TemplateArgument(TemplateName(TTP), llvm::Optional<unsigned>());
198 else
199 Arg = TemplateArgument(TemplateName(TTP));
200 }
201
202 if ((*Param)->isTemplateParameterPack())
203 Arg = TemplateArgument::CreatePackCopy(Context, &Arg, 1);
204
205 *Args++ = Arg;
206 }
207}
208
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000209//===----------------------------------------------------------------------===//
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000210// FunctionTemplateDecl Implementation
211//===----------------------------------------------------------------------===//
212
Douglas Gregor00545312010-05-23 18:26:36 +0000213void FunctionTemplateDecl::DeallocateCommon(void *Ptr) {
214 static_cast<Common *>(Ptr)->~Common();
215}
216
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000217FunctionTemplateDecl *FunctionTemplateDecl::Create(ASTContext &C,
218 DeclContext *DC,
219 SourceLocation L,
220 DeclarationName Name,
Douglas Gregor127102b2009-06-29 20:59:39 +0000221 TemplateParameterList *Params,
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000222 NamedDecl *Decl) {
Douglas Gregor787a40d2011-03-04 18:32:38 +0000223 AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000224 return new (C) FunctionTemplateDecl(DC, L, Name, Params, Decl);
225}
226
Douglas Gregor9a299e02011-03-04 17:52:15 +0000227FunctionTemplateDecl *FunctionTemplateDecl::Create(ASTContext &C, EmptyShell) {
228 return new (C) FunctionTemplateDecl(0, SourceLocation(), DeclarationName(),
229 0, 0);
230}
231
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000232RedeclarableTemplateDecl::CommonBase *
233FunctionTemplateDecl::newCommon(ASTContext &C) {
234 Common *CommonPtr = new (C) Common;
235 C.AddDeallocation(DeallocateCommon, CommonPtr);
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000236 return CommonPtr;
237}
238
Argyrios Kyrtzidis2c853e42010-07-20 13:59:58 +0000239FunctionDecl *
240FunctionTemplateDecl::findSpecialization(const TemplateArgument *Args,
241 unsigned NumArgs, void *&InsertPos) {
Peter Collingbourne40485902010-07-30 17:09:04 +0000242 return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos);
Argyrios Kyrtzidis2c853e42010-07-20 13:59:58 +0000243}
244
Sebastian Redl5bbcdbf2011-04-14 14:07:59 +0000245void FunctionTemplateDecl::addSpecialization(
246 FunctionTemplateSpecializationInfo *Info, void *InsertPos) {
247 getSpecializations().InsertNode(Info, InsertPos);
248 if (ASTMutationListener *L = getASTMutationListener())
249 L->AddedCXXTemplateSpecialization(this, Info->Function);
250}
251
Douglas Gregorc494f772011-03-05 17:54:25 +0000252std::pair<const TemplateArgument *, unsigned>
253FunctionTemplateDecl::getInjectedTemplateArgs() {
254 TemplateParameterList *Params = getTemplateParameters();
255 Common *CommonPtr = getCommonPtr();
256 if (!CommonPtr->InjectedArgs) {
257 CommonPtr->InjectedArgs
258 = new (getASTContext()) TemplateArgument [Params->size()];
259 GenerateInjectedTemplateArgs(getASTContext(), Params,
260 CommonPtr->InjectedArgs);
261 }
262
263 return std::make_pair(CommonPtr->InjectedArgs, Params->size());
264}
265
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000266//===----------------------------------------------------------------------===//
267// ClassTemplateDecl Implementation
268//===----------------------------------------------------------------------===//
269
Douglas Gregor00545312010-05-23 18:26:36 +0000270void ClassTemplateDecl::DeallocateCommon(void *Ptr) {
271 static_cast<Common *>(Ptr)->~Common();
272}
273
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000274ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext &C,
275 DeclContext *DC,
276 SourceLocation L,
277 DeclarationName Name,
278 TemplateParameterList *Params,
Douglas Gregor5953d8b2009-03-19 17:26:29 +0000279 NamedDecl *Decl,
280 ClassTemplateDecl *PrevDecl) {
Douglas Gregor787a40d2011-03-04 18:32:38 +0000281 AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000282 ClassTemplateDecl *New = new (C) ClassTemplateDecl(DC, L, Name, Params, Decl);
Argyrios Kyrtzidis5bf1bdc2010-06-21 10:57:41 +0000283 New->setPreviousDeclaration(PrevDecl);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000284 return New;
Douglas Gregor5953d8b2009-03-19 17:26:29 +0000285}
286
Douglas Gregor9a299e02011-03-04 17:52:15 +0000287ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext &C, EmptyShell Empty) {
288 return new (C) ClassTemplateDecl(Empty);
289}
290
Douglas Gregorc8e5cf82010-10-27 22:21:36 +0000291void ClassTemplateDecl::LoadLazySpecializations() {
292 Common *CommonPtr = getCommonPtr();
293 if (CommonPtr->LazySpecializations) {
294 ASTContext &Context = getASTContext();
295 uint32_t *Specs = CommonPtr->LazySpecializations;
296 CommonPtr->LazySpecializations = 0;
297 for (uint32_t I = 0, N = *Specs++; I != N; ++I)
298 (void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
299 }
300}
301
302llvm::FoldingSet<ClassTemplateSpecializationDecl> &
303ClassTemplateDecl::getSpecializations() {
304 LoadLazySpecializations();
305 return getCommonPtr()->Specializations;
306}
307
308llvm::FoldingSet<ClassTemplatePartialSpecializationDecl> &
309ClassTemplateDecl::getPartialSpecializations() {
310 LoadLazySpecializations();
311 return getCommonPtr()->PartialSpecializations;
312}
313
Argyrios Kyrtzidis6b541512010-09-08 19:31:22 +0000314RedeclarableTemplateDecl::CommonBase *
315ClassTemplateDecl::newCommon(ASTContext &C) {
316 Common *CommonPtr = new (C) Common;
317 C.AddDeallocation(DeallocateCommon, CommonPtr);
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000318 return CommonPtr;
319}
320
Argyrios Kyrtzidiscc0b1bc2010-07-20 13:59:28 +0000321ClassTemplateSpecializationDecl *
322ClassTemplateDecl::findSpecialization(const TemplateArgument *Args,
323 unsigned NumArgs, void *&InsertPos) {
Peter Collingbourne40485902010-07-30 17:09:04 +0000324 return findSpecializationImpl(getSpecializations(), Args, NumArgs, InsertPos);
Argyrios Kyrtzidiscc0b1bc2010-07-20 13:59:28 +0000325}
326
Argyrios Kyrtzidisbef1a7b2010-10-28 07:38:42 +0000327void ClassTemplateDecl::AddSpecialization(ClassTemplateSpecializationDecl *D,
328 void *InsertPos) {
329 getSpecializations().InsertNode(D, InsertPos);
330 if (ASTMutationListener *L = getASTMutationListener())
331 L->AddedCXXTemplateSpecialization(this, D);
332}
333
Argyrios Kyrtzidiscc0b1bc2010-07-20 13:59:28 +0000334ClassTemplatePartialSpecializationDecl *
335ClassTemplateDecl::findPartialSpecialization(const TemplateArgument *Args,
336 unsigned NumArgs,
337 void *&InsertPos) {
Peter Collingbourne40485902010-07-30 17:09:04 +0000338 return findSpecializationImpl(getPartialSpecializations(), Args, NumArgs,
339 InsertPos);
Argyrios Kyrtzidiscc0b1bc2010-07-20 13:59:28 +0000340}
341
Argyrios Kyrtzidisbef1a7b2010-10-28 07:38:42 +0000342void ClassTemplateDecl::AddPartialSpecialization(
343 ClassTemplatePartialSpecializationDecl *D,
344 void *InsertPos) {
345 getPartialSpecializations().InsertNode(D, InsertPos);
346 if (ASTMutationListener *L = getASTMutationListener())
347 L->AddedCXXTemplateSpecialization(this, D);
348}
349
Douglas Gregordc60c1e2010-04-30 05:56:50 +0000350void ClassTemplateDecl::getPartialSpecializations(
Chris Lattner5f9e2722011-07-23 10:55:15 +0000351 SmallVectorImpl<ClassTemplatePartialSpecializationDecl *> &PS) {
Douglas Gregordc60c1e2010-04-30 05:56:50 +0000352 llvm::FoldingSet<ClassTemplatePartialSpecializationDecl> &PartialSpecs
Argyrios Kyrtzidis5bf1bdc2010-06-21 10:57:41 +0000353 = getPartialSpecializations();
Douglas Gregordc60c1e2010-04-30 05:56:50 +0000354 PS.clear();
355 PS.resize(PartialSpecs.size());
356 for (llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator
357 P = PartialSpecs.begin(), PEnd = PartialSpecs.end();
358 P != PEnd; ++P) {
359 assert(!PS[P->getSequenceNumber()]);
Argyrios Kyrtzidiscc0b1bc2010-07-20 13:59:28 +0000360 PS[P->getSequenceNumber()] = P->getMostRecentDeclaration();
Douglas Gregordc60c1e2010-04-30 05:56:50 +0000361 }
362}
363
Douglas Gregorb88e8882009-07-30 17:40:51 +0000364ClassTemplatePartialSpecializationDecl *
365ClassTemplateDecl::findPartialSpecialization(QualType T) {
366 ASTContext &Context = getASTContext();
367 typedef llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator
368 partial_spec_iterator;
369 for (partial_spec_iterator P = getPartialSpecializations().begin(),
370 PEnd = getPartialSpecializations().end();
371 P != PEnd; ++P) {
John McCall31f17ec2010-04-27 00:57:59 +0000372 if (Context.hasSameType(P->getInjectedSpecializationType(), T))
Argyrios Kyrtzidiscc0b1bc2010-07-20 13:59:28 +0000373 return P->getMostRecentDeclaration();
374 }
375
376 return 0;
377}
378
379ClassTemplatePartialSpecializationDecl *
380ClassTemplateDecl::findPartialSpecInstantiatedFromMember(
381 ClassTemplatePartialSpecializationDecl *D) {
382 Decl *DCanon = D->getCanonicalDecl();
383 for (llvm::FoldingSet<ClassTemplatePartialSpecializationDecl>::iterator
384 P = getPartialSpecializations().begin(),
385 PEnd = getPartialSpecializations().end();
386 P != PEnd; ++P) {
387 if (P->getInstantiatedFromMember()->getCanonicalDecl() == DCanon)
388 return P->getMostRecentDeclaration();
Douglas Gregorb88e8882009-07-30 17:40:51 +0000389 }
Mike Stump1eb44332009-09-09 15:08:12 +0000390
Douglas Gregorb88e8882009-07-30 17:40:51 +0000391 return 0;
392}
393
John McCall3cb0ebd2010-03-10 03:28:59 +0000394QualType
Douglas Gregor24bae922010-07-08 18:37:38 +0000395ClassTemplateDecl::getInjectedClassNameSpecialization() {
Argyrios Kyrtzidis5bf1bdc2010-06-21 10:57:41 +0000396 Common *CommonPtr = getCommonPtr();
Douglas Gregor7da97d02009-05-10 22:57:19 +0000397 if (!CommonPtr->InjectedClassNameType.isNull())
398 return CommonPtr->InjectedClassNameType;
399
Douglas Gregorb7d09d62010-12-23 16:00:30 +0000400 // C++0x [temp.dep.type]p2:
401 // The template argument list of a primary template is a template argument
402 // list in which the nth template argument has the value of the nth template
403 // parameter of the class template. If the nth template parameter is a
404 // template parameter pack (14.5.3), the nth template argument is a pack
405 // expansion (14.5.3) whose pattern is the name of the template parameter
406 // pack.
Douglas Gregor24bae922010-07-08 18:37:38 +0000407 ASTContext &Context = getASTContext();
Douglas Gregor7da97d02009-05-10 22:57:19 +0000408 TemplateParameterList *Params = getTemplateParameters();
Chris Lattner5f9e2722011-07-23 10:55:15 +0000409 SmallVector<TemplateArgument, 16> TemplateArgs;
Douglas Gregorc494f772011-03-05 17:54:25 +0000410 TemplateArgs.resize(Params->size());
411 GenerateInjectedTemplateArgs(getASTContext(), Params, TemplateArgs.data());
Douglas Gregor7da97d02009-05-10 22:57:19 +0000412 CommonPtr->InjectedClassNameType
Douglas Gregor1275ae02009-07-28 23:00:59 +0000413 = Context.getTemplateSpecializationType(TemplateName(this),
Douglas Gregor7da97d02009-05-10 22:57:19 +0000414 &TemplateArgs[0],
Douglas Gregor1275ae02009-07-28 23:00:59 +0000415 TemplateArgs.size());
Douglas Gregor7da97d02009-05-10 22:57:19 +0000416 return CommonPtr->InjectedClassNameType;
417}
418
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000419//===----------------------------------------------------------------------===//
420// TemplateTypeParm Allocation/Deallocation Method Implementations
421//===----------------------------------------------------------------------===//
422
423TemplateTypeParmDecl *
Jay Foad4ba2a172011-01-12 09:06:06 +0000424TemplateTypeParmDecl::Create(const ASTContext &C, DeclContext *DC,
Abramo Bagnara344577e2011-03-06 15:48:19 +0000425 SourceLocation KeyLoc, SourceLocation NameLoc,
426 unsigned D, unsigned P, IdentifierInfo *Id,
427 bool Typename, bool ParameterPack) {
Chandler Carruth4fb86f82011-05-01 00:51:33 +0000428 TemplateTypeParmDecl *TTPDecl =
429 new (C) TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename);
430 QualType TTPType = C.getTemplateTypeParmType(D, P, ParameterPack, TTPDecl);
431 TTPDecl->TypeForDecl = TTPType.getTypePtr();
432 return TTPDecl;
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000433}
434
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +0000435TemplateTypeParmDecl *
Jay Foad4ba2a172011-01-12 09:06:06 +0000436TemplateTypeParmDecl::Create(const ASTContext &C, EmptyShell Empty) {
Abramo Bagnara344577e2011-03-06 15:48:19 +0000437 return new (C) TemplateTypeParmDecl(0, SourceLocation(), SourceLocation(),
Chandler Carruth4fb86f82011-05-01 00:51:33 +0000438 0, false);
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +0000439}
440
John McCall833ca992009-10-29 08:12:44 +0000441SourceLocation TemplateTypeParmDecl::getDefaultArgumentLoc() const {
Abramo Bagnara77d4ee22011-03-04 12:42:03 +0000442 return hasDefaultArgument()
443 ? DefaultArgument->getTypeLoc().getBeginLoc()
444 : SourceLocation();
445}
446
447SourceRange TemplateTypeParmDecl::getSourceRange() const {
448 if (hasDefaultArgument() && !defaultArgumentWasInherited())
Abramo Bagnara344577e2011-03-06 15:48:19 +0000449 return SourceRange(getLocStart(),
Abramo Bagnara77d4ee22011-03-04 12:42:03 +0000450 DefaultArgument->getTypeLoc().getEndLoc());
451 else
Abramo Bagnara344577e2011-03-06 15:48:19 +0000452 return TypeDecl::getSourceRange();
John McCall833ca992009-10-29 08:12:44 +0000453}
454
Douglas Gregored9c0f92009-10-29 00:04:11 +0000455unsigned TemplateTypeParmDecl::getDepth() const {
456 return TypeForDecl->getAs<TemplateTypeParmType>()->getDepth();
457}
458
459unsigned TemplateTypeParmDecl::getIndex() const {
460 return TypeForDecl->getAs<TemplateTypeParmType>()->getIndex();
461}
462
Chandler Carruth4fb86f82011-05-01 00:51:33 +0000463bool TemplateTypeParmDecl::isParameterPack() const {
464 return TypeForDecl->getAs<TemplateTypeParmType>()->isParameterPack();
465}
466
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000467//===----------------------------------------------------------------------===//
468// NonTypeTemplateParmDecl Method Implementations
469//===----------------------------------------------------------------------===//
470
Douglas Gregor6952f1e2011-01-19 20:10:05 +0000471NonTypeTemplateParmDecl::NonTypeTemplateParmDecl(DeclContext *DC,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +0000472 SourceLocation StartLoc,
473 SourceLocation IdLoc,
474 unsigned D, unsigned P,
475 IdentifierInfo *Id,
Douglas Gregor6952f1e2011-01-19 20:10:05 +0000476 QualType T,
477 TypeSourceInfo *TInfo,
478 const QualType *ExpandedTypes,
479 unsigned NumExpandedTypes,
480 TypeSourceInfo **ExpandedTInfos)
Abramo Bagnaraff676cb2011-03-08 08:55:46 +0000481 : DeclaratorDecl(NonTypeTemplateParm, DC, IdLoc, Id, T, TInfo, StartLoc),
Douglas Gregor6952f1e2011-01-19 20:10:05 +0000482 TemplateParmPosition(D, P), DefaultArgumentAndInherited(0, false),
483 ParameterPack(true), ExpandedParameterPack(true),
484 NumExpandedTypes(NumExpandedTypes)
485{
486 if (ExpandedTypes && ExpandedTInfos) {
487 void **TypesAndInfos = reinterpret_cast<void **>(this + 1);
488 for (unsigned I = 0; I != NumExpandedTypes; ++I) {
489 TypesAndInfos[2*I] = ExpandedTypes[I].getAsOpaquePtr();
490 TypesAndInfos[2*I + 1] = ExpandedTInfos[I];
491 }
492 }
493}
494
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000495NonTypeTemplateParmDecl *
Jay Foad4ba2a172011-01-12 09:06:06 +0000496NonTypeTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +0000497 SourceLocation StartLoc, SourceLocation IdLoc,
498 unsigned D, unsigned P, IdentifierInfo *Id,
499 QualType T, bool ParameterPack,
500 TypeSourceInfo *TInfo) {
501 return new (C) NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id,
502 T, ParameterPack, TInfo);
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000503}
504
Douglas Gregor6952f1e2011-01-19 20:10:05 +0000505NonTypeTemplateParmDecl *
506NonTypeTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +0000507 SourceLocation StartLoc, SourceLocation IdLoc,
508 unsigned D, unsigned P,
Douglas Gregor6952f1e2011-01-19 20:10:05 +0000509 IdentifierInfo *Id, QualType T,
510 TypeSourceInfo *TInfo,
511 const QualType *ExpandedTypes,
512 unsigned NumExpandedTypes,
513 TypeSourceInfo **ExpandedTInfos) {
514 unsigned Size = sizeof(NonTypeTemplateParmDecl)
515 + NumExpandedTypes * 2 * sizeof(void*);
516 void *Mem = C.Allocate(Size);
Abramo Bagnaraff676cb2011-03-08 08:55:46 +0000517 return new (Mem) NonTypeTemplateParmDecl(DC, StartLoc, IdLoc,
518 D, P, Id, T, TInfo,
Douglas Gregor6952f1e2011-01-19 20:10:05 +0000519 ExpandedTypes, NumExpandedTypes,
520 ExpandedTInfos);
521}
522
John McCall76a40212011-02-09 01:13:10 +0000523SourceRange NonTypeTemplateParmDecl::getSourceRange() const {
Abramo Bagnaraee4bfd42011-03-04 11:03:48 +0000524 if (hasDefaultArgument() && !defaultArgumentWasInherited())
Abramo Bagnaraa2026c92011-03-08 16:41:52 +0000525 return SourceRange(getOuterLocStart(),
526 getDefaultArgument()->getSourceRange().getEnd());
527 return DeclaratorDecl::getSourceRange();
John McCall76a40212011-02-09 01:13:10 +0000528}
529
Douglas Gregord684b002009-02-10 19:49:53 +0000530SourceLocation NonTypeTemplateParmDecl::getDefaultArgumentLoc() const {
Abramo Bagnarad92f7a22010-06-09 09:26:05 +0000531 return hasDefaultArgument()
532 ? getDefaultArgument()->getSourceRange().getBegin()
533 : SourceLocation();
Douglas Gregord684b002009-02-10 19:49:53 +0000534}
535
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000536//===----------------------------------------------------------------------===//
537// TemplateTemplateParmDecl Method Implementations
538//===----------------------------------------------------------------------===//
539
540TemplateTemplateParmDecl *
Jay Foad4ba2a172011-01-12 09:06:06 +0000541TemplateTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC,
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000542 SourceLocation L, unsigned D, unsigned P,
Douglas Gregor61c4d282011-01-05 15:48:55 +0000543 bool ParameterPack, IdentifierInfo *Id,
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000544 TemplateParameterList *Params) {
Douglas Gregor61c4d282011-01-05 15:48:55 +0000545 return new (C) TemplateTemplateParmDecl(DC, L, D, P, ParameterPack, Id,
546 Params);
Douglas Gregoraaba5e32009-02-04 19:02:06 +0000547}
548
Douglas Gregor3e00bad2009-02-17 01:05:43 +0000549//===----------------------------------------------------------------------===//
Douglas Gregor7e063902009-05-11 23:53:27 +0000550// TemplateArgumentList Implementation
551//===----------------------------------------------------------------------===//
Douglas Gregor910f8002010-11-07 23:05:16 +0000552TemplateArgumentList *
553TemplateArgumentList::CreateCopy(ASTContext &Context,
554 const TemplateArgument *Args,
555 unsigned NumArgs) {
556 std::size_t Size = sizeof(TemplateArgumentList)
557 + NumArgs * sizeof(TemplateArgument);
558 void *Mem = Context.Allocate(Size);
559 TemplateArgument *StoredArgs
560 = reinterpret_cast<TemplateArgument *>(
561 static_cast<TemplateArgumentList *>(Mem) + 1);
562 std::uninitialized_copy(Args, Args + NumArgs, StoredArgs);
563 return new (Mem) TemplateArgumentList(StoredArgs, NumArgs, true);
Argyrios Kyrtzidis94d228d2010-06-23 13:48:23 +0000564}
565
Douglas Gregor7e063902009-05-11 23:53:27 +0000566//===----------------------------------------------------------------------===//
Douglas Gregor3e00bad2009-02-17 01:05:43 +0000567// ClassTemplateSpecializationDecl Implementation
568//===----------------------------------------------------------------------===//
569ClassTemplateSpecializationDecl::
Douglas Gregor13c85772010-05-06 00:28:52 +0000570ClassTemplateSpecializationDecl(ASTContext &Context, Kind DK, TagKind TK,
Abramo Bagnaraba877ad2011-03-09 14:09:51 +0000571 DeclContext *DC, SourceLocation StartLoc,
572 SourceLocation IdLoc,
Douglas Gregor3e00bad2009-02-17 01:05:43 +0000573 ClassTemplateDecl *SpecializedTemplate,
Douglas Gregor910f8002010-11-07 23:05:16 +0000574 const TemplateArgument *Args,
575 unsigned NumArgs,
Douglas Gregor8e9e9ef2009-07-29 23:36:44 +0000576 ClassTemplateSpecializationDecl *PrevDecl)
Abramo Bagnaraba877ad2011-03-09 14:09:51 +0000577 : CXXRecordDecl(DK, TK, DC, StartLoc, IdLoc,
Douglas Gregor8e9e9ef2009-07-29 23:36:44 +0000578 SpecializedTemplate->getIdentifier(),
579 PrevDecl),
Douglas Gregor3e00bad2009-02-17 01:05:43 +0000580 SpecializedTemplate(SpecializedTemplate),
Abramo Bagnarac98971d2010-06-12 07:44:57 +0000581 ExplicitInfo(0),
Douglas Gregor910f8002010-11-07 23:05:16 +0000582 TemplateArgs(TemplateArgumentList::CreateCopy(Context, Args, NumArgs)),
Douglas Gregor7e063902009-05-11 23:53:27 +0000583 SpecializationKind(TSK_Undeclared) {
Douglas Gregor3e00bad2009-02-17 01:05:43 +0000584}
Mike Stump1eb44332009-09-09 15:08:12 +0000585
Argyrios Kyrtzidis94d228d2010-06-23 13:48:23 +0000586ClassTemplateSpecializationDecl::ClassTemplateSpecializationDecl(Kind DK)
Abramo Bagnaraba877ad2011-03-09 14:09:51 +0000587 : CXXRecordDecl(DK, TTK_Struct, 0, SourceLocation(), SourceLocation(), 0, 0),
Argyrios Kyrtzidis94d228d2010-06-23 13:48:23 +0000588 ExplicitInfo(0),
589 SpecializationKind(TSK_Undeclared) {
590}
591
Douglas Gregor3e00bad2009-02-17 01:05:43 +0000592ClassTemplateSpecializationDecl *
Douglas Gregor13c85772010-05-06 00:28:52 +0000593ClassTemplateSpecializationDecl::Create(ASTContext &Context, TagKind TK,
Abramo Bagnaraba877ad2011-03-09 14:09:51 +0000594 DeclContext *DC,
595 SourceLocation StartLoc,
596 SourceLocation IdLoc,
Douglas Gregor3e00bad2009-02-17 01:05:43 +0000597 ClassTemplateDecl *SpecializedTemplate,
Douglas Gregor910f8002010-11-07 23:05:16 +0000598 const TemplateArgument *Args,
599 unsigned NumArgs,
Douglas Gregorcc636682009-02-17 23:15:12 +0000600 ClassTemplateSpecializationDecl *PrevDecl) {
Douglas Gregorcc636682009-02-17 23:15:12 +0000601 ClassTemplateSpecializationDecl *Result
Mike Stump1eb44332009-09-09 15:08:12 +0000602 = new (Context)ClassTemplateSpecializationDecl(Context,
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000603 ClassTemplateSpecialization,
Abramo Bagnaraba877ad2011-03-09 14:09:51 +0000604 TK, DC, StartLoc, IdLoc,
Douglas Gregor7e063902009-05-11 23:53:27 +0000605 SpecializedTemplate,
Douglas Gregor910f8002010-11-07 23:05:16 +0000606 Args, NumArgs,
Douglas Gregor8e9e9ef2009-07-29 23:36:44 +0000607 PrevDecl);
Douglas Gregorcc636682009-02-17 23:15:12 +0000608 Context.getTypeDeclType(Result, PrevDecl);
609 return Result;
Douglas Gregor3e00bad2009-02-17 01:05:43 +0000610}
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000611
Argyrios Kyrtzidis94d228d2010-06-23 13:48:23 +0000612ClassTemplateSpecializationDecl *
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +0000613ClassTemplateSpecializationDecl::Create(ASTContext &Context, EmptyShell Empty) {
Argyrios Kyrtzidis94d228d2010-06-23 13:48:23 +0000614 return
615 new (Context)ClassTemplateSpecializationDecl(ClassTemplateSpecialization);
616}
617
Douglas Gregorda2142f2011-02-19 18:51:44 +0000618void
619ClassTemplateSpecializationDecl::getNameForDiagnostic(std::string &S,
620 const PrintingPolicy &Policy,
621 bool Qualified) const {
622 NamedDecl::getNameForDiagnostic(S, Policy, Qualified);
623
624 const TemplateArgumentList &TemplateArgs = getTemplateArgs();
625 S += TemplateSpecializationType::PrintTemplateArgumentList(
626 TemplateArgs.data(),
627 TemplateArgs.size(),
628 Policy);
629}
630
Douglas Gregor37d93e92009-08-02 23:24:31 +0000631ClassTemplateDecl *
Mike Stump1eb44332009-09-09 15:08:12 +0000632ClassTemplateSpecializationDecl::getSpecializedTemplate() const {
633 if (SpecializedPartialSpecialization *PartialSpec
Douglas Gregor37d93e92009-08-02 23:24:31 +0000634 = SpecializedTemplate.dyn_cast<SpecializedPartialSpecialization*>())
635 return PartialSpec->PartialSpecialization->getSpecializedTemplate();
636 return SpecializedTemplate.get<ClassTemplateDecl*>();
637}
638
Abramo Bagnara4a85a732011-03-04 14:20:30 +0000639SourceRange
640ClassTemplateSpecializationDecl::getSourceRange() const {
641 if (!ExplicitInfo)
642 return SourceRange();
643 SourceLocation Begin = getExternLoc();
644 if (Begin.isInvalid())
645 Begin = getTemplateKeywordLoc();
646 SourceLocation End = getRBraceLoc();
647 if (End.isInvalid())
648 End = getTypeAsWritten()->getTypeLoc().getEndLoc();
649 return SourceRange(Begin, End);
650}
651
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000652//===----------------------------------------------------------------------===//
653// ClassTemplatePartialSpecializationDecl Implementation
654//===----------------------------------------------------------------------===//
Douglas Gregor9a299e02011-03-04 17:52:15 +0000655ClassTemplatePartialSpecializationDecl::
656ClassTemplatePartialSpecializationDecl(ASTContext &Context, TagKind TK,
Abramo Bagnaraba877ad2011-03-09 14:09:51 +0000657 DeclContext *DC,
658 SourceLocation StartLoc,
659 SourceLocation IdLoc,
Douglas Gregor9a299e02011-03-04 17:52:15 +0000660 TemplateParameterList *Params,
661 ClassTemplateDecl *SpecializedTemplate,
662 const TemplateArgument *Args,
663 unsigned NumArgs,
664 TemplateArgumentLoc *ArgInfos,
665 unsigned NumArgInfos,
666 ClassTemplatePartialSpecializationDecl *PrevDecl,
667 unsigned SequenceNumber)
668 : ClassTemplateSpecializationDecl(Context,
669 ClassTemplatePartialSpecialization,
Abramo Bagnaraba877ad2011-03-09 14:09:51 +0000670 TK, DC, StartLoc, IdLoc,
671 SpecializedTemplate,
Douglas Gregor9a299e02011-03-04 17:52:15 +0000672 Args, NumArgs, PrevDecl),
673 TemplateParams(Params), ArgsAsWritten(ArgInfos),
674 NumArgsAsWritten(NumArgInfos), SequenceNumber(SequenceNumber),
675 InstantiatedFromMember(0, false)
676{
Douglas Gregor787a40d2011-03-04 18:32:38 +0000677 AdoptTemplateParameterList(Params, this);
Douglas Gregor9a299e02011-03-04 17:52:15 +0000678}
679
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000680ClassTemplatePartialSpecializationDecl *
681ClassTemplatePartialSpecializationDecl::
Abramo Bagnaraba877ad2011-03-09 14:09:51 +0000682Create(ASTContext &Context, TagKind TK,DeclContext *DC,
683 SourceLocation StartLoc, SourceLocation IdLoc,
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000684 TemplateParameterList *Params,
685 ClassTemplateDecl *SpecializedTemplate,
Douglas Gregor910f8002010-11-07 23:05:16 +0000686 const TemplateArgument *Args,
687 unsigned NumArgs,
John McCalld5532b62009-11-23 01:53:49 +0000688 const TemplateArgumentListInfo &ArgInfos,
John McCall3cb0ebd2010-03-10 03:28:59 +0000689 QualType CanonInjectedType,
Douglas Gregordc60c1e2010-04-30 05:56:50 +0000690 ClassTemplatePartialSpecializationDecl *PrevDecl,
691 unsigned SequenceNumber) {
John McCalld5532b62009-11-23 01:53:49 +0000692 unsigned N = ArgInfos.size();
John McCall833ca992009-10-29 08:12:44 +0000693 TemplateArgumentLoc *ClonedArgs = new (Context) TemplateArgumentLoc[N];
694 for (unsigned I = 0; I != N; ++I)
695 ClonedArgs[I] = ArgInfos[I];
696
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000697 ClassTemplatePartialSpecializationDecl *Result
Abramo Bagnaraba877ad2011-03-09 14:09:51 +0000698 = new (Context)ClassTemplatePartialSpecializationDecl(Context, TK, DC,
699 StartLoc, IdLoc,
700 Params,
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000701 SpecializedTemplate,
Douglas Gregor910f8002010-11-07 23:05:16 +0000702 Args, NumArgs,
John McCall833ca992009-10-29 08:12:44 +0000703 ClonedArgs, N,
Douglas Gregordc60c1e2010-04-30 05:56:50 +0000704 PrevDecl,
705 SequenceNumber);
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000706 Result->setSpecializationKind(TSK_ExplicitSpecialization);
John McCall3cb0ebd2010-03-10 03:28:59 +0000707
708 Context.getInjectedClassNameType(Result, CanonInjectedType);
Douglas Gregorc8ab2562009-05-31 09:31:02 +0000709 return Result;
710}
John McCalldd4a3b02009-09-16 22:47:08 +0000711
Argyrios Kyrtzidis94d228d2010-06-23 13:48:23 +0000712ClassTemplatePartialSpecializationDecl *
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +0000713ClassTemplatePartialSpecializationDecl::Create(ASTContext &Context,
714 EmptyShell Empty) {
Argyrios Kyrtzidis94d228d2010-06-23 13:48:23 +0000715 return new (Context)ClassTemplatePartialSpecializationDecl();
716}
717
John McCalldd4a3b02009-09-16 22:47:08 +0000718//===----------------------------------------------------------------------===//
719// FriendTemplateDecl Implementation
720//===----------------------------------------------------------------------===//
721
722FriendTemplateDecl *FriendTemplateDecl::Create(ASTContext &Context,
723 DeclContext *DC,
724 SourceLocation L,
725 unsigned NParams,
726 TemplateParameterList **Params,
727 FriendUnion Friend,
728 SourceLocation FLoc) {
729 FriendTemplateDecl *Result
730 = new (Context) FriendTemplateDecl(DC, L, NParams, Params, Friend, FLoc);
731 return Result;
732}
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +0000733
734FriendTemplateDecl *FriendTemplateDecl::Create(ASTContext &Context,
735 EmptyShell Empty) {
736 return new (Context) FriendTemplateDecl(Empty);
737}
Richard Smith3e4c6c42011-05-05 21:57:07 +0000738
739//===----------------------------------------------------------------------===//
740// TypeAliasTemplateDecl Implementation
741//===----------------------------------------------------------------------===//
742
743TypeAliasTemplateDecl *TypeAliasTemplateDecl::Create(ASTContext &C,
744 DeclContext *DC,
745 SourceLocation L,
746 DeclarationName Name,
747 TemplateParameterList *Params,
748 NamedDecl *Decl) {
749 AdoptTemplateParameterList(Params, DC);
750 return new (C) TypeAliasTemplateDecl(DC, L, Name, Params, Decl);
751}
752
753TypeAliasTemplateDecl *TypeAliasTemplateDecl::Create(ASTContext &C,
754 EmptyShell) {
755 return new (C) TypeAliasTemplateDecl(0, SourceLocation(), DeclarationName(),
756 0, 0);
757}
758
759void TypeAliasTemplateDecl::DeallocateCommon(void *Ptr) {
760 static_cast<Common *>(Ptr)->~Common();
761}
762RedeclarableTemplateDecl::CommonBase *
763TypeAliasTemplateDecl::newCommon(ASTContext &C) {
764 Common *CommonPtr = new (C) Common;
765 C.AddDeallocation(DeallocateCommon, CommonPtr);
766 return CommonPtr;
767}
768