blob: 95655d85c33416b51bcb45e0b3db9b04606cb949 [file] [log] [blame]
Douglas Gregor8dbc2692009-03-17 21:15:40 +00001//===--- SemaTemplateInstantiateDecl.cpp - C++ Template Decl Instantiation ===/
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// This file implements C++ template instantiation for declarations.
10//
11//===----------------------------------------------------------------------===/
12#include "Sema.h"
Douglas Gregoraba43bb2009-05-26 20:50:29 +000013#include "clang/AST/ASTConsumer.h"
Douglas Gregor8dbc2692009-03-17 21:15:40 +000014#include "clang/AST/ASTContext.h"
15#include "clang/AST/DeclTemplate.h"
16#include "clang/AST/DeclVisitor.h"
17#include "clang/AST/Expr.h"
18#include "llvm/Support/Compiler.h"
19
20using namespace clang;
21
22namespace {
23 class VISIBILITY_HIDDEN TemplateDeclInstantiator
Chris Lattnerb28317a2009-03-28 19:18:32 +000024 : public DeclVisitor<TemplateDeclInstantiator, Decl *> {
Douglas Gregor8dbc2692009-03-17 21:15:40 +000025 Sema &SemaRef;
26 DeclContext *Owner;
Douglas Gregor7e063902009-05-11 23:53:27 +000027 const TemplateArgumentList &TemplateArgs;
Douglas Gregor8dbc2692009-03-17 21:15:40 +000028
29 public:
30 typedef Sema::OwningExprResult OwningExprResult;
31
32 TemplateDeclInstantiator(Sema &SemaRef, DeclContext *Owner,
Douglas Gregor7e063902009-05-11 23:53:27 +000033 const TemplateArgumentList &TemplateArgs)
34 : SemaRef(SemaRef), Owner(Owner), TemplateArgs(TemplateArgs) { }
Douglas Gregor8dbc2692009-03-17 21:15:40 +000035
Mike Stump390b4cc2009-05-16 07:39:55 +000036 // FIXME: Once we get closer to completion, replace these manually-written
37 // declarations with automatically-generated ones from
38 // clang/AST/DeclNodes.def.
Douglas Gregor4f722be2009-03-25 15:45:12 +000039 Decl *VisitTranslationUnitDecl(TranslationUnitDecl *D);
40 Decl *VisitNamespaceDecl(NamespaceDecl *D);
Douglas Gregor8dbc2692009-03-17 21:15:40 +000041 Decl *VisitTypedefDecl(TypedefDecl *D);
Douglas Gregor3d7a12a2009-03-25 23:32:15 +000042 Decl *VisitVarDecl(VarDecl *D);
Douglas Gregor8dbc2692009-03-17 21:15:40 +000043 Decl *VisitFieldDecl(FieldDecl *D);
44 Decl *VisitStaticAssertDecl(StaticAssertDecl *D);
45 Decl *VisitEnumDecl(EnumDecl *D);
Douglas Gregor6477b692009-03-25 15:04:13 +000046 Decl *VisitEnumConstantDecl(EnumConstantDecl *D);
Douglas Gregore53060f2009-06-25 22:08:12 +000047 Decl *VisitFunctionDecl(FunctionDecl *D);
Douglas Gregord475b8d2009-03-25 21:17:03 +000048 Decl *VisitCXXRecordDecl(CXXRecordDecl *D);
Douglas Gregor2dc0e642009-03-23 23:06:20 +000049 Decl *VisitCXXMethodDecl(CXXMethodDecl *D);
Douglas Gregor615c5d42009-03-24 16:43:20 +000050 Decl *VisitCXXConstructorDecl(CXXConstructorDecl *D);
Douglas Gregor03b2b072009-03-24 00:15:49 +000051 Decl *VisitCXXDestructorDecl(CXXDestructorDecl *D);
Douglas Gregorbb969ed2009-03-25 00:34:44 +000052 Decl *VisitCXXConversionDecl(CXXConversionDecl *D);
Douglas Gregor6477b692009-03-25 15:04:13 +000053 ParmVarDecl *VisitParmVarDecl(ParmVarDecl *D);
Douglas Gregor2dc0e642009-03-23 23:06:20 +000054 Decl *VisitOriginalParmVarDecl(OriginalParmVarDecl *D);
Douglas Gregor5545e162009-03-24 00:38:23 +000055
Douglas Gregor8dbc2692009-03-17 21:15:40 +000056 // Base case. FIXME: Remove once we can instantiate everything.
57 Decl *VisitDecl(Decl *) {
Douglas Gregor3d7a12a2009-03-25 23:32:15 +000058 assert(false && "Template instantiation of unknown declaration kind!");
Douglas Gregor8dbc2692009-03-17 21:15:40 +000059 return 0;
60 }
Douglas Gregor5545e162009-03-24 00:38:23 +000061
62 // Helper functions for instantiating methods.
63 QualType InstantiateFunctionType(FunctionDecl *D,
64 llvm::SmallVectorImpl<ParmVarDecl *> &Params);
Douglas Gregore53060f2009-06-25 22:08:12 +000065 bool InitFunctionInstantiation(FunctionDecl *New, FunctionDecl *Tmpl);
Douglas Gregor5545e162009-03-24 00:38:23 +000066 bool InitMethodInstantiation(CXXMethodDecl *New, CXXMethodDecl *Tmpl);
Douglas Gregor8dbc2692009-03-17 21:15:40 +000067 };
68}
69
Douglas Gregor4f722be2009-03-25 15:45:12 +000070Decl *
71TemplateDeclInstantiator::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
72 assert(false && "Translation units cannot be instantiated");
73 return D;
74}
75
76Decl *
77TemplateDeclInstantiator::VisitNamespaceDecl(NamespaceDecl *D) {
78 assert(false && "Namespaces cannot be instantiated");
79 return D;
80}
81
Douglas Gregor8dbc2692009-03-17 21:15:40 +000082Decl *TemplateDeclInstantiator::VisitTypedefDecl(TypedefDecl *D) {
83 bool Invalid = false;
84 QualType T = D->getUnderlyingType();
85 if (T->isDependentType()) {
Douglas Gregor1eee0e72009-05-14 21:06:31 +000086 T = SemaRef.InstantiateType(T, TemplateArgs,
87 D->getLocation(), D->getDeclName());
Douglas Gregor8dbc2692009-03-17 21:15:40 +000088 if (T.isNull()) {
89 Invalid = true;
90 T = SemaRef.Context.IntTy;
91 }
92 }
93
94 // Create the new typedef
95 TypedefDecl *Typedef
96 = TypedefDecl::Create(SemaRef.Context, Owner, D->getLocation(),
97 D->getIdentifier(), T);
98 if (Invalid)
99 Typedef->setInvalidDecl();
100
Douglas Gregor6ab35242009-04-09 21:40:53 +0000101 Owner->addDecl(SemaRef.Context, Typedef);
Douglas Gregorbc221632009-05-28 16:34:51 +0000102
Douglas Gregor8dbc2692009-03-17 21:15:40 +0000103 return Typedef;
104}
105
Douglas Gregor3d7a12a2009-03-25 23:32:15 +0000106Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D) {
107 // Instantiate the type of the declaration
108 QualType T = SemaRef.InstantiateType(D->getType(), TemplateArgs,
Douglas Gregor3d7a12a2009-03-25 23:32:15 +0000109 D->getTypeSpecStartLoc(),
110 D->getDeclName());
111 if (T.isNull())
112 return 0;
113
Douglas Gregorb9f1b8d2009-05-15 00:01:03 +0000114 // Build the instantiated declaration
Douglas Gregor3d7a12a2009-03-25 23:32:15 +0000115 VarDecl *Var = VarDecl::Create(SemaRef.Context, Owner,
116 D->getLocation(), D->getIdentifier(),
117 T, D->getStorageClass(),
118 D->getTypeSpecStartLoc());
119 Var->setThreadSpecified(D->isThreadSpecified());
120 Var->setCXXDirectInitializer(D->hasCXXDirectInitializer());
121 Var->setDeclaredInCondition(D->isDeclaredInCondition());
122
Mike Stump390b4cc2009-05-16 07:39:55 +0000123 // FIXME: In theory, we could have a previous declaration for variables that
124 // are not static data members.
Douglas Gregor3d7a12a2009-03-25 23:32:15 +0000125 bool Redeclaration = false;
Chris Lattnereaaebc72009-04-25 08:06:05 +0000126 SemaRef.CheckVariableDeclaration(Var, 0, Redeclaration);
Douglas Gregor6ab35242009-04-09 21:40:53 +0000127 Owner->addDecl(SemaRef.Context, Var);
Douglas Gregor3d7a12a2009-03-25 23:32:15 +0000128
129 if (D->getInit()) {
130 OwningExprResult Init
Douglas Gregor7e063902009-05-11 23:53:27 +0000131 = SemaRef.InstantiateExpr(D->getInit(), TemplateArgs);
Douglas Gregor3d7a12a2009-03-25 23:32:15 +0000132 if (Init.isInvalid())
133 Var->setInvalidDecl();
134 else
Chris Lattnerb28317a2009-03-28 19:18:32 +0000135 SemaRef.AddInitializerToDecl(Sema::DeclPtrTy::make(Var), move(Init),
Douglas Gregor3d7a12a2009-03-25 23:32:15 +0000136 D->hasCXXDirectInitializer());
Douglas Gregord308e622009-05-18 20:51:54 +0000137 } else {
138 // FIXME: Call ActOnUninitializedDecl? (Not always)
Douglas Gregor3d7a12a2009-03-25 23:32:15 +0000139 }
140
141 return Var;
142}
143
Douglas Gregor8dbc2692009-03-17 21:15:40 +0000144Decl *TemplateDeclInstantiator::VisitFieldDecl(FieldDecl *D) {
145 bool Invalid = false;
146 QualType T = D->getType();
147 if (T->isDependentType()) {
Douglas Gregor1eee0e72009-05-14 21:06:31 +0000148 T = SemaRef.InstantiateType(T, TemplateArgs,
149 D->getLocation(), D->getDeclName());
Douglas Gregor8dbc2692009-03-17 21:15:40 +0000150 if (!T.isNull() && T->isFunctionType()) {
151 // C++ [temp.arg.type]p3:
152 // If a declaration acquires a function type through a type
153 // dependent on a template-parameter and this causes a
154 // declaration that does not use the syntactic form of a
155 // function declarator to have function type, the program is
156 // ill-formed.
157 SemaRef.Diag(D->getLocation(), diag::err_field_instantiates_to_function)
158 << T;
159 T = QualType();
160 Invalid = true;
161 }
162 }
163
164 Expr *BitWidth = D->getBitWidth();
165 if (Invalid)
166 BitWidth = 0;
167 else if (BitWidth) {
Douglas Gregorac7610d2009-06-22 20:57:11 +0000168 // The bit-width expression is not potentially evaluated.
169 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
170
Douglas Gregor8dbc2692009-03-17 21:15:40 +0000171 OwningExprResult InstantiatedBitWidth
Douglas Gregor7e063902009-05-11 23:53:27 +0000172 = SemaRef.InstantiateExpr(BitWidth, TemplateArgs);
Douglas Gregor8dbc2692009-03-17 21:15:40 +0000173 if (InstantiatedBitWidth.isInvalid()) {
174 Invalid = true;
175 BitWidth = 0;
176 } else
Anders Carlssone9146f22009-05-01 19:49:17 +0000177 BitWidth = InstantiatedBitWidth.takeAs<Expr>();
Douglas Gregor8dbc2692009-03-17 21:15:40 +0000178 }
179
180 FieldDecl *Field = SemaRef.CheckFieldDecl(D->getDeclName(), T,
181 cast<RecordDecl>(Owner),
182 D->getLocation(),
183 D->isMutable(),
184 BitWidth,
185 D->getAccess(),
186 0);
187 if (Field) {
188 if (Invalid)
189 Field->setInvalidDecl();
190
Douglas Gregor6ab35242009-04-09 21:40:53 +0000191 Owner->addDecl(SemaRef.Context, Field);
Douglas Gregor8dbc2692009-03-17 21:15:40 +0000192 }
193
194 return Field;
195}
196
197Decl *TemplateDeclInstantiator::VisitStaticAssertDecl(StaticAssertDecl *D) {
198 Expr *AssertExpr = D->getAssertExpr();
199
Douglas Gregorac7610d2009-06-22 20:57:11 +0000200 // The expression in a static assertion is not potentially evaluated.
201 EnterExpressionEvaluationContext Unevaluated(SemaRef, Action::Unevaluated);
202
Douglas Gregor8dbc2692009-03-17 21:15:40 +0000203 OwningExprResult InstantiatedAssertExpr
Douglas Gregor7e063902009-05-11 23:53:27 +0000204 = SemaRef.InstantiateExpr(AssertExpr, TemplateArgs);
Douglas Gregor8dbc2692009-03-17 21:15:40 +0000205 if (InstantiatedAssertExpr.isInvalid())
206 return 0;
207
208 OwningExprResult Message = SemaRef.Clone(D->getMessage());
209 Decl *StaticAssert
Chris Lattnerb28317a2009-03-28 19:18:32 +0000210 = SemaRef.ActOnStaticAssertDeclaration(D->getLocation(),
211 move(InstantiatedAssertExpr),
212 move(Message)).getAs<Decl>();
Douglas Gregor8dbc2692009-03-17 21:15:40 +0000213 return StaticAssert;
214}
215
216Decl *TemplateDeclInstantiator::VisitEnumDecl(EnumDecl *D) {
217 EnumDecl *Enum = EnumDecl::Create(SemaRef.Context, Owner,
218 D->getLocation(), D->getIdentifier(),
219 /*PrevDecl=*/0);
Douglas Gregor8dbc3c62009-05-27 17:20:35 +0000220 Enum->setInstantiationOfMemberEnum(D);
Douglas Gregor06c0fec2009-03-25 22:00:53 +0000221 Enum->setAccess(D->getAccess());
Douglas Gregor6ab35242009-04-09 21:40:53 +0000222 Owner->addDecl(SemaRef.Context, Enum);
Douglas Gregor8dbc2692009-03-17 21:15:40 +0000223 Enum->startDefinition();
224
Douglas Gregor0ca20ac2009-05-29 18:27:38 +0000225 llvm::SmallVector<Sema::DeclPtrTy, 4> Enumerators;
Douglas Gregor8dbc2692009-03-17 21:15:40 +0000226
227 EnumConstantDecl *LastEnumConst = 0;
Douglas Gregor6ab35242009-04-09 21:40:53 +0000228 for (EnumDecl::enumerator_iterator EC = D->enumerator_begin(SemaRef.Context),
229 ECEnd = D->enumerator_end(SemaRef.Context);
Douglas Gregor8dbc2692009-03-17 21:15:40 +0000230 EC != ECEnd; ++EC) {
231 // The specified value for the enumerator.
232 OwningExprResult Value = SemaRef.Owned((Expr *)0);
Douglas Gregorac7610d2009-06-22 20:57:11 +0000233 if (Expr *UninstValue = EC->getInitExpr()) {
234 // The enumerator's value expression is not potentially evaluated.
235 EnterExpressionEvaluationContext Unevaluated(SemaRef,
236 Action::Unevaluated);
237
Douglas Gregor7e063902009-05-11 23:53:27 +0000238 Value = SemaRef.InstantiateExpr(UninstValue, TemplateArgs);
Douglas Gregorac7610d2009-06-22 20:57:11 +0000239 }
Douglas Gregor8dbc2692009-03-17 21:15:40 +0000240
241 // Drop the initial value and continue.
242 bool isInvalid = false;
243 if (Value.isInvalid()) {
244 Value = SemaRef.Owned((Expr *)0);
245 isInvalid = true;
246 }
247
248 EnumConstantDecl *EnumConst
249 = SemaRef.CheckEnumConstant(Enum, LastEnumConst,
250 EC->getLocation(), EC->getIdentifier(),
251 move(Value));
252
253 if (isInvalid) {
254 if (EnumConst)
255 EnumConst->setInvalidDecl();
256 Enum->setInvalidDecl();
257 }
258
259 if (EnumConst) {
Douglas Gregor6ab35242009-04-09 21:40:53 +0000260 Enum->addDecl(SemaRef.Context, EnumConst);
Chris Lattnerb28317a2009-03-28 19:18:32 +0000261 Enumerators.push_back(Sema::DeclPtrTy::make(EnumConst));
Douglas Gregor8dbc2692009-03-17 21:15:40 +0000262 LastEnumConst = EnumConst;
263 }
264 }
265
Mike Stumpc6e35aa2009-05-16 07:06:02 +0000266 // FIXME: Fixup LBraceLoc and RBraceLoc
267 SemaRef.ActOnEnumBody(Enum->getLocation(), SourceLocation(), SourceLocation(),
268 Sema::DeclPtrTy::make(Enum),
Douglas Gregor8dbc2692009-03-17 21:15:40 +0000269 &Enumerators[0], Enumerators.size());
270
271 return Enum;
272}
273
Douglas Gregor6477b692009-03-25 15:04:13 +0000274Decl *TemplateDeclInstantiator::VisitEnumConstantDecl(EnumConstantDecl *D) {
275 assert(false && "EnumConstantDecls can only occur within EnumDecls.");
276 return 0;
277}
278
Douglas Gregord475b8d2009-03-25 21:17:03 +0000279Decl *TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) {
280 CXXRecordDecl *PrevDecl = 0;
281 if (D->isInjectedClassName())
282 PrevDecl = cast<CXXRecordDecl>(Owner);
283
284 CXXRecordDecl *Record
285 = CXXRecordDecl::Create(SemaRef.Context, D->getTagKind(), Owner,
286 D->getLocation(), D->getIdentifier(), PrevDecl);
287 Record->setImplicit(D->isImplicit());
288 Record->setAccess(D->getAccess());
Douglas Gregord475b8d2009-03-25 21:17:03 +0000289 if (!D->isInjectedClassName())
290 Record->setInstantiationOfMemberClass(D);
291
Douglas Gregor6ab35242009-04-09 21:40:53 +0000292 Owner->addDecl(SemaRef.Context, Record);
Douglas Gregord475b8d2009-03-25 21:17:03 +0000293 return Record;
294}
295
Douglas Gregore53060f2009-06-25 22:08:12 +0000296Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D) {
297 // FIXME: Look for existing specializations (explicit or otherwise).
298
299 Sema::LocalInstantiationScope Scope(SemaRef);
300
301 llvm::SmallVector<ParmVarDecl *, 4> Params;
302 QualType T = InstantiateFunctionType(D, Params);
303 if (T.isNull())
Douglas Gregor2dc0e642009-03-23 23:06:20 +0000304 return 0;
Douglas Gregore53060f2009-06-25 22:08:12 +0000305
306 // Build the instantiated method declaration.
307 FunctionDecl *Function
308 = FunctionDecl::Create(SemaRef.Context, Owner, D->getLocation(),
309 D->getDeclName(), T, D->getStorageClass(),
310 D->isInline(), D->hasWrittenPrototype(),
311 D->getTypeSpecStartLoc());
312
313 // FIXME: friend functions
314
315 // Attach the parameters
316 for (unsigned P = 0; P < Params.size(); ++P)
317 Params[P]->setOwningFunction(Function);
318 Function->setParams(SemaRef.Context, Params.data(), Params.size());
319
320 if (InitFunctionInstantiation(Function, D))
321 Function->setInvalidDecl();
322
323 bool Redeclaration = false;
324 bool OverloadableAttrRequired = false;
325 NamedDecl *PrevDecl = 0;
326 SemaRef.CheckFunctionDeclaration(Function, PrevDecl, Redeclaration,
327 /*FIXME:*/OverloadableAttrRequired);
328
Douglas Gregor2dc0e642009-03-23 23:06:20 +0000329
Douglas Gregore53060f2009-06-25 22:08:12 +0000330 // FIXME: link this to the function template from which it was instantiated.
331
332 return Function;
333}
334
335Decl *TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D) {
336 // FIXME: Look for existing, explicit specializations.
Douglas Gregor48dd19b2009-05-14 21:44:34 +0000337 Sema::LocalInstantiationScope Scope(SemaRef);
338
Douglas Gregor0ca20ac2009-05-29 18:27:38 +0000339 llvm::SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregor5545e162009-03-24 00:38:23 +0000340 QualType T = InstantiateFunctionType(D, Params);
Douglas Gregor2dc0e642009-03-23 23:06:20 +0000341 if (T.isNull())
342 return 0;
343
344 // Build the instantiated method declaration.
345 CXXRecordDecl *Record = cast<CXXRecordDecl>(Owner);
346 CXXMethodDecl *Method
347 = CXXMethodDecl::Create(SemaRef.Context, Record, D->getLocation(),
348 D->getDeclName(), T, D->isStatic(),
349 D->isInline());
Douglas Gregor1eee0e72009-05-14 21:06:31 +0000350 Method->setInstantiationOfMemberFunction(D);
Douglas Gregor2dc0e642009-03-23 23:06:20 +0000351
Douglas Gregor5545e162009-03-24 00:38:23 +0000352 // Attach the parameters
353 for (unsigned P = 0; P < Params.size(); ++P)
354 Params[P]->setOwningFunction(Method);
Jay Foadbeaaccd2009-05-21 09:52:38 +0000355 Method->setParams(SemaRef.Context, Params.data(), Params.size());
Douglas Gregor5545e162009-03-24 00:38:23 +0000356
357 if (InitMethodInstantiation(Method, D))
358 Method->setInvalidDecl();
Douglas Gregor2dc0e642009-03-23 23:06:20 +0000359
360 NamedDecl *PrevDecl
361 = SemaRef.LookupQualifiedName(Owner, Method->getDeclName(),
362 Sema::LookupOrdinaryName, true);
363 // In C++, the previous declaration we find might be a tag type
364 // (class or enum). In this case, the new declaration will hide the
365 // tag type. Note that this does does not apply if we're declaring a
366 // typedef (C++ [dcl.typedef]p4).
367 if (PrevDecl && PrevDecl->getIdentifierNamespace() == Decl::IDNS_Tag)
368 PrevDecl = 0;
369 bool Redeclaration = false;
370 bool OverloadableAttrRequired = false;
Chris Lattnereaaebc72009-04-25 08:06:05 +0000371 SemaRef.CheckFunctionDeclaration(Method, PrevDecl, Redeclaration,
372 /*FIXME:*/OverloadableAttrRequired);
Douglas Gregor2dc0e642009-03-23 23:06:20 +0000373
374 if (!Method->isInvalidDecl() || !PrevDecl)
Douglas Gregor6ab35242009-04-09 21:40:53 +0000375 Owner->addDecl(SemaRef.Context, Method);
Douglas Gregor2dc0e642009-03-23 23:06:20 +0000376 return Method;
377}
378
Douglas Gregor615c5d42009-03-24 16:43:20 +0000379Decl *TemplateDeclInstantiator::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Douglas Gregore53060f2009-06-25 22:08:12 +0000380 // FIXME: Look for existing, explicit specializations.
Douglas Gregor48dd19b2009-05-14 21:44:34 +0000381 Sema::LocalInstantiationScope Scope(SemaRef);
382
Douglas Gregor0ca20ac2009-05-29 18:27:38 +0000383 llvm::SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregor615c5d42009-03-24 16:43:20 +0000384 QualType T = InstantiateFunctionType(D, Params);
385 if (T.isNull())
386 return 0;
387
388 // Build the instantiated method declaration.
389 CXXRecordDecl *Record = cast<CXXRecordDecl>(Owner);
390 QualType ClassTy = SemaRef.Context.getTypeDeclType(Record);
391 DeclarationName Name
Douglas Gregor49f25ec2009-05-15 21:18:27 +0000392 = SemaRef.Context.DeclarationNames.getCXXConstructorName(
393 SemaRef.Context.getCanonicalType(ClassTy));
Douglas Gregor615c5d42009-03-24 16:43:20 +0000394 CXXConstructorDecl *Constructor
395 = CXXConstructorDecl::Create(SemaRef.Context, Record, D->getLocation(),
396 Name, T, D->isExplicit(), D->isInline(),
397 false);
Douglas Gregor1eee0e72009-05-14 21:06:31 +0000398 Constructor->setInstantiationOfMemberFunction(D);
Douglas Gregor615c5d42009-03-24 16:43:20 +0000399
400 // Attach the parameters
401 for (unsigned P = 0; P < Params.size(); ++P)
402 Params[P]->setOwningFunction(Constructor);
Jay Foadbeaaccd2009-05-21 09:52:38 +0000403 Constructor->setParams(SemaRef.Context, Params.data(), Params.size());
Douglas Gregor615c5d42009-03-24 16:43:20 +0000404
405 if (InitMethodInstantiation(Constructor, D))
406 Constructor->setInvalidDecl();
407
408 NamedDecl *PrevDecl
409 = SemaRef.LookupQualifiedName(Owner, Name, Sema::LookupOrdinaryName, true);
410
411 // In C++, the previous declaration we find might be a tag type
412 // (class or enum). In this case, the new declaration will hide the
413 // tag type. Note that this does does not apply if we're declaring a
414 // typedef (C++ [dcl.typedef]p4).
415 if (PrevDecl && PrevDecl->getIdentifierNamespace() == Decl::IDNS_Tag)
416 PrevDecl = 0;
417 bool Redeclaration = false;
418 bool OverloadableAttrRequired = false;
Chris Lattnereaaebc72009-04-25 08:06:05 +0000419 SemaRef.CheckFunctionDeclaration(Constructor, PrevDecl, Redeclaration,
420 /*FIXME:*/OverloadableAttrRequired);
Douglas Gregor615c5d42009-03-24 16:43:20 +0000421
Douglas Gregor49f25ec2009-05-15 21:18:27 +0000422 Record->addedConstructor(SemaRef.Context, Constructor);
Chris Lattnereaaebc72009-04-25 08:06:05 +0000423 Owner->addDecl(SemaRef.Context, Constructor);
Douglas Gregor615c5d42009-03-24 16:43:20 +0000424 return Constructor;
425}
426
Douglas Gregor03b2b072009-03-24 00:15:49 +0000427Decl *TemplateDeclInstantiator::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Douglas Gregore53060f2009-06-25 22:08:12 +0000428 // FIXME: Look for existing, explicit specializations.
Douglas Gregor48dd19b2009-05-14 21:44:34 +0000429 Sema::LocalInstantiationScope Scope(SemaRef);
430
Douglas Gregor0ca20ac2009-05-29 18:27:38 +0000431 llvm::SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregor5545e162009-03-24 00:38:23 +0000432 QualType T = InstantiateFunctionType(D, Params);
Douglas Gregor03b2b072009-03-24 00:15:49 +0000433 if (T.isNull())
434 return 0;
Douglas Gregor5545e162009-03-24 00:38:23 +0000435 assert(Params.size() == 0 && "Destructor with parameters?");
436
Douglas Gregor03b2b072009-03-24 00:15:49 +0000437 // Build the instantiated destructor declaration.
438 CXXRecordDecl *Record = cast<CXXRecordDecl>(Owner);
Douglas Gregor49f25ec2009-05-15 21:18:27 +0000439 QualType ClassTy =
440 SemaRef.Context.getCanonicalType(SemaRef.Context.getTypeDeclType(Record));
Douglas Gregor03b2b072009-03-24 00:15:49 +0000441 CXXDestructorDecl *Destructor
442 = CXXDestructorDecl::Create(SemaRef.Context, Record,
443 D->getLocation(),
444 SemaRef.Context.DeclarationNames.getCXXDestructorName(ClassTy),
445 T, D->isInline(), false);
Douglas Gregor1eee0e72009-05-14 21:06:31 +0000446 Destructor->setInstantiationOfMemberFunction(D);
Douglas Gregor5545e162009-03-24 00:38:23 +0000447 if (InitMethodInstantiation(Destructor, D))
448 Destructor->setInvalidDecl();
Douglas Gregor03b2b072009-03-24 00:15:49 +0000449
450 bool Redeclaration = false;
451 bool OverloadableAttrRequired = false;
452 NamedDecl *PrevDecl = 0;
Chris Lattnereaaebc72009-04-25 08:06:05 +0000453 SemaRef.CheckFunctionDeclaration(Destructor, PrevDecl, Redeclaration,
454 /*FIXME:*/OverloadableAttrRequired);
Douglas Gregor6ab35242009-04-09 21:40:53 +0000455 Owner->addDecl(SemaRef.Context, Destructor);
Douglas Gregor03b2b072009-03-24 00:15:49 +0000456 return Destructor;
457}
458
Douglas Gregorbb969ed2009-03-25 00:34:44 +0000459Decl *TemplateDeclInstantiator::VisitCXXConversionDecl(CXXConversionDecl *D) {
Douglas Gregore53060f2009-06-25 22:08:12 +0000460 // FIXME: Look for existing, explicit specializations.
Douglas Gregor48dd19b2009-05-14 21:44:34 +0000461 Sema::LocalInstantiationScope Scope(SemaRef);
462
Douglas Gregor0ca20ac2009-05-29 18:27:38 +0000463 llvm::SmallVector<ParmVarDecl *, 4> Params;
Douglas Gregorbb969ed2009-03-25 00:34:44 +0000464 QualType T = InstantiateFunctionType(D, Params);
465 if (T.isNull())
466 return 0;
467 assert(Params.size() == 0 && "Destructor with parameters?");
468
469 // Build the instantiated conversion declaration.
470 CXXRecordDecl *Record = cast<CXXRecordDecl>(Owner);
471 QualType ClassTy = SemaRef.Context.getTypeDeclType(Record);
472 QualType ConvTy
473 = SemaRef.Context.getCanonicalType(T->getAsFunctionType()->getResultType());
474 CXXConversionDecl *Conversion
475 = CXXConversionDecl::Create(SemaRef.Context, Record,
476 D->getLocation(),
477 SemaRef.Context.DeclarationNames.getCXXConversionFunctionName(ConvTy),
478 T, D->isInline(), D->isExplicit());
Douglas Gregor1eee0e72009-05-14 21:06:31 +0000479 Conversion->setInstantiationOfMemberFunction(D);
Douglas Gregorbb969ed2009-03-25 00:34:44 +0000480 if (InitMethodInstantiation(Conversion, D))
481 Conversion->setInvalidDecl();
482
483 bool Redeclaration = false;
484 bool OverloadableAttrRequired = false;
485 NamedDecl *PrevDecl = 0;
Chris Lattnereaaebc72009-04-25 08:06:05 +0000486 SemaRef.CheckFunctionDeclaration(Conversion, PrevDecl, Redeclaration,
487 /*FIXME:*/OverloadableAttrRequired);
Douglas Gregor6ab35242009-04-09 21:40:53 +0000488 Owner->addDecl(SemaRef.Context, Conversion);
Douglas Gregorbb969ed2009-03-25 00:34:44 +0000489 return Conversion;
490}
491
Douglas Gregor6477b692009-03-25 15:04:13 +0000492ParmVarDecl *TemplateDeclInstantiator::VisitParmVarDecl(ParmVarDecl *D) {
Douglas Gregor2dc0e642009-03-23 23:06:20 +0000493 QualType OrigT = SemaRef.InstantiateType(D->getOriginalType(), TemplateArgs,
Douglas Gregor7e063902009-05-11 23:53:27 +0000494 D->getLocation(), D->getDeclName());
Douglas Gregor2dc0e642009-03-23 23:06:20 +0000495 if (OrigT.isNull())
496 return 0;
497
498 QualType T = SemaRef.adjustParameterType(OrigT);
499
500 if (D->getDefaultArg()) {
501 // FIXME: Leave a marker for "uninstantiated" default
502 // arguments. They only get instantiated on demand at the call
503 // site.
504 unsigned DiagID = SemaRef.Diags.getCustomDiagID(Diagnostic::Warning,
505 "sorry, dropping default argument during template instantiation");
506 SemaRef.Diag(D->getDefaultArg()->getSourceRange().getBegin(), DiagID)
507 << D->getDefaultArg()->getSourceRange();
508 }
509
510 // Allocate the parameter
511 ParmVarDecl *Param = 0;
512 if (T == OrigT)
513 Param = ParmVarDecl::Create(SemaRef.Context, Owner, D->getLocation(),
514 D->getIdentifier(), T, D->getStorageClass(),
515 0);
516 else
517 Param = OriginalParmVarDecl::Create(SemaRef.Context, Owner,
518 D->getLocation(), D->getIdentifier(),
519 T, OrigT, D->getStorageClass(), 0);
520
521 // Note: we don't try to instantiate function parameters until after
522 // we've instantiated the function's type. Therefore, we don't have
523 // to check for 'void' parameter types here.
Douglas Gregor48dd19b2009-05-14 21:44:34 +0000524 SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Param);
Douglas Gregor2dc0e642009-03-23 23:06:20 +0000525 return Param;
526}
527
528Decl *
529TemplateDeclInstantiator::VisitOriginalParmVarDecl(OriginalParmVarDecl *D) {
530 // Since parameter types can decay either before or after
531 // instantiation, we simply treat OriginalParmVarDecls as
532 // ParmVarDecls the same way, and create one or the other depending
533 // on what happens after template instantiation.
534 return VisitParmVarDecl(D);
535}
536
Douglas Gregor8dbc2692009-03-17 21:15:40 +0000537Decl *Sema::InstantiateDecl(Decl *D, DeclContext *Owner,
Douglas Gregor7e063902009-05-11 23:53:27 +0000538 const TemplateArgumentList &TemplateArgs) {
539 TemplateDeclInstantiator Instantiator(*this, Owner, TemplateArgs);
Douglas Gregor8dbc2692009-03-17 21:15:40 +0000540 return Instantiator.Visit(D);
541}
542
Douglas Gregor5545e162009-03-24 00:38:23 +0000543/// \brief Instantiates the type of the given function, including
544/// instantiating all of the function parameters.
545///
546/// \param D The function that we will be instantiated
547///
548/// \param Params the instantiated parameter declarations
549
550/// \returns the instantiated function's type if successfull, a NULL
551/// type if there was an error.
552QualType
553TemplateDeclInstantiator::InstantiateFunctionType(FunctionDecl *D,
554 llvm::SmallVectorImpl<ParmVarDecl *> &Params) {
555 bool InvalidDecl = false;
556
557 // Instantiate the function parameters
Douglas Gregor7e063902009-05-11 23:53:27 +0000558 TemplateDeclInstantiator ParamInstantiator(SemaRef, 0, TemplateArgs);
Douglas Gregor0ca20ac2009-05-29 18:27:38 +0000559 llvm::SmallVector<QualType, 4> ParamTys;
Douglas Gregor5545e162009-03-24 00:38:23 +0000560 for (FunctionDecl::param_iterator P = D->param_begin(),
561 PEnd = D->param_end();
562 P != PEnd; ++P) {
Douglas Gregor6477b692009-03-25 15:04:13 +0000563 if (ParmVarDecl *PInst = ParamInstantiator.VisitParmVarDecl(*P)) {
Douglas Gregor5545e162009-03-24 00:38:23 +0000564 if (PInst->getType()->isVoidType()) {
565 SemaRef.Diag(PInst->getLocation(), diag::err_param_with_void_type);
566 PInst->setInvalidDecl();
567 }
568 else if (SemaRef.RequireNonAbstractType(PInst->getLocation(),
569 PInst->getType(),
570 diag::err_abstract_type_in_decl,
Anders Carlsson8211eff2009-03-24 01:19:16 +0000571 Sema::AbstractParamType))
Douglas Gregor5545e162009-03-24 00:38:23 +0000572 PInst->setInvalidDecl();
573
574 Params.push_back(PInst);
575 ParamTys.push_back(PInst->getType());
576
577 if (PInst->isInvalidDecl())
578 InvalidDecl = true;
579 } else
580 InvalidDecl = true;
581 }
582
583 // FIXME: Deallocate dead declarations.
584 if (InvalidDecl)
585 return QualType();
586
587 const FunctionProtoType *Proto = D->getType()->getAsFunctionProtoType();
588 assert(Proto && "Missing prototype?");
589 QualType ResultType
Douglas Gregor1eee0e72009-05-14 21:06:31 +0000590 = SemaRef.InstantiateType(Proto->getResultType(), TemplateArgs,
Douglas Gregor5545e162009-03-24 00:38:23 +0000591 D->getLocation(), D->getDeclName());
592 if (ResultType.isNull())
593 return QualType();
594
Jay Foadbeaaccd2009-05-21 09:52:38 +0000595 return SemaRef.BuildFunctionType(ResultType, ParamTys.data(), ParamTys.size(),
Douglas Gregor5545e162009-03-24 00:38:23 +0000596 Proto->isVariadic(), Proto->getTypeQuals(),
597 D->getLocation(), D->getDeclName());
598}
599
Douglas Gregore53060f2009-06-25 22:08:12 +0000600/// \brief Initializes the common fields of an instantiation function
601/// declaration (New) from the corresponding fields of its template (Tmpl).
602///
603/// \returns true if there was an error
604bool
605TemplateDeclInstantiator::InitFunctionInstantiation(FunctionDecl *New,
606 FunctionDecl *Tmpl) {
607 if (Tmpl->isDeleted())
608 New->setDeleted();
609 return false;
610}
611
Douglas Gregor5545e162009-03-24 00:38:23 +0000612/// \brief Initializes common fields of an instantiated method
613/// declaration (New) from the corresponding fields of its template
614/// (Tmpl).
615///
616/// \returns true if there was an error
617bool
618TemplateDeclInstantiator::InitMethodInstantiation(CXXMethodDecl *New,
619 CXXMethodDecl *Tmpl) {
Douglas Gregore53060f2009-06-25 22:08:12 +0000620 if (InitFunctionInstantiation(New, Tmpl))
621 return true;
622
Douglas Gregor5545e162009-03-24 00:38:23 +0000623 CXXRecordDecl *Record = cast<CXXRecordDecl>(Owner);
624 New->setAccess(Tmpl->getAccess());
Anders Carlsson77b7f1d2009-05-14 22:15:41 +0000625 if (Tmpl->isVirtualAsWritten()) {
626 New->setVirtualAsWritten(true);
Douglas Gregor5545e162009-03-24 00:38:23 +0000627 Record->setAggregate(false);
628 Record->setPOD(false);
629 Record->setPolymorphic(true);
630 }
Douglas Gregor5545e162009-03-24 00:38:23 +0000631 if (Tmpl->isPure()) {
632 New->setPure();
633 Record->setAbstract(true);
634 }
635
636 // FIXME: attributes
637 // FIXME: New needs a pointer to Tmpl
638 return false;
639}
Douglas Gregora58861f2009-05-13 20:28:22 +0000640
641/// \brief Instantiate the definition of the given function from its
642/// template.
643///
644/// \param Function the already-instantiated declaration of a
645/// function.
Douglas Gregorf3e7ce42009-05-18 17:01:57 +0000646void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
647 FunctionDecl *Function) {
Douglas Gregor1eee0e72009-05-14 21:06:31 +0000648 // FIXME: make this work for function template specializations, too.
649
Douglas Gregor54dabfc2009-05-14 23:26:13 +0000650 if (Function->isInvalidDecl())
651 return;
652
Douglas Gregord7f37bf2009-06-22 23:06:13 +0000653 assert(!Function->getBody(Context) && "Already instantiated!");
654
Douglas Gregor1eee0e72009-05-14 21:06:31 +0000655 // Find the function body that we'll be substituting.
656 const FunctionDecl *PatternDecl
657 = Function->getInstantiatedFromMemberFunction();
658 Stmt *Pattern = 0;
659 if (PatternDecl)
660 Pattern = PatternDecl->getBody(Context, PatternDecl);
661
662 if (!Pattern)
663 return;
664
Douglas Gregorf3e7ce42009-05-18 17:01:57 +0000665 InstantiatingTemplate Inst(*this, PointOfInstantiation, Function);
666 if (Inst)
667 return;
Douglas Gregorb9f1b8d2009-05-15 00:01:03 +0000668
Douglas Gregore2c31ff2009-05-15 17:59:04 +0000669 ActOnStartOfFunctionDef(0, DeclPtrTy::make(Function));
670
Douglas Gregor54dabfc2009-05-14 23:26:13 +0000671 // Introduce a new scope where local variable instantiations will be
672 // recorded.
673 LocalInstantiationScope Scope(*this);
674
675 // Introduce the instantiated function parameters into the local
676 // instantiation scope.
677 for (unsigned I = 0, N = PatternDecl->getNumParams(); I != N; ++I)
678 Scope.InstantiatedLocal(PatternDecl->getParamDecl(I),
679 Function->getParamDecl(I));
680
Douglas Gregorb9f1b8d2009-05-15 00:01:03 +0000681 // Enter the scope of this instantiation. We don't use
682 // PushDeclContext because we don't have a scope.
683 DeclContext *PreviousContext = CurContext;
684 CurContext = Function;
685
Douglas Gregor54dabfc2009-05-14 23:26:13 +0000686 // Instantiate the function body.
687 OwningStmtResult Body
688 = InstantiateStmt(Pattern, getTemplateInstantiationArgs(Function));
Douglas Gregore2c31ff2009-05-15 17:59:04 +0000689
690 ActOnFinishFunctionBody(DeclPtrTy::make(Function), move(Body),
691 /*IsInstantiation=*/true);
Douglas Gregorb9f1b8d2009-05-15 00:01:03 +0000692
693 CurContext = PreviousContext;
Douglas Gregoraba43bb2009-05-26 20:50:29 +0000694
695 DeclGroupRef DG(Function);
696 Consumer.HandleTopLevelDecl(DG);
Douglas Gregora58861f2009-05-13 20:28:22 +0000697}
698
699/// \brief Instantiate the definition of the given variable from its
700/// template.
701///
702/// \param Var the already-instantiated declaration of a variable.
703void Sema::InstantiateVariableDefinition(VarDecl *Var) {
704 // FIXME: Implement this!
705}
Douglas Gregor815215d2009-05-27 05:35:12 +0000706
707static bool isInstantiationOf(ASTContext &Ctx, NamedDecl *D, Decl *Other) {
708 if (D->getKind() != Other->getKind())
709 return false;
710
711 if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(Other))
712 return Ctx.getCanonicalDecl(Record->getInstantiatedFromMemberClass())
713 == Ctx.getCanonicalDecl(D);
714
715 if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Other))
716 return Ctx.getCanonicalDecl(Function->getInstantiatedFromMemberFunction())
717 == Ctx.getCanonicalDecl(D);
718
Douglas Gregor8dbc3c62009-05-27 17:20:35 +0000719 if (EnumDecl *Enum = dyn_cast<EnumDecl>(Other))
720 return Ctx.getCanonicalDecl(Enum->getInstantiatedFromMemberEnum())
721 == Ctx.getCanonicalDecl(D);
Douglas Gregor815215d2009-05-27 05:35:12 +0000722
723 // FIXME: How can we find instantiations of anonymous unions?
724
725 return D->getDeclName() && isa<NamedDecl>(Other) &&
726 D->getDeclName() == cast<NamedDecl>(Other)->getDeclName();
727}
728
729template<typename ForwardIterator>
730static NamedDecl *findInstantiationOf(ASTContext &Ctx,
731 NamedDecl *D,
732 ForwardIterator first,
733 ForwardIterator last) {
734 for (; first != last; ++first)
735 if (isInstantiationOf(Ctx, D, *first))
736 return cast<NamedDecl>(*first);
737
738 return 0;
739}
740
Douglas Gregored961e72009-05-27 17:54:46 +0000741/// \brief Find the instantiation of the given declaration within the
742/// current instantiation.
Douglas Gregor815215d2009-05-27 05:35:12 +0000743///
744/// This routine is intended to be used when \p D is a declaration
745/// referenced from within a template, that needs to mapped into the
746/// corresponding declaration within an instantiation. For example,
747/// given:
748///
749/// \code
750/// template<typename T>
751/// struct X {
752/// enum Kind {
753/// KnownValue = sizeof(T)
754/// };
755///
756/// bool getKind() const { return KnownValue; }
757/// };
758///
759/// template struct X<int>;
760/// \endcode
761///
762/// In the instantiation of X<int>::getKind(), we need to map the
763/// EnumConstantDecl for KnownValue (which refers to
764/// X<T>::<Kind>::KnownValue) to its instantiation
Douglas Gregored961e72009-05-27 17:54:46 +0000765/// (X<int>::<Kind>::KnownValue). InstantiateCurrentDeclRef() performs
766/// this mapping from within the instantiation of X<int>.
767NamedDecl * Sema::InstantiateCurrentDeclRef(NamedDecl *D) {
Douglas Gregor815215d2009-05-27 05:35:12 +0000768 DeclContext *ParentDC = D->getDeclContext();
Douglas Gregor2bba76b2009-05-27 17:07:49 +0000769 if (isa<ParmVarDecl>(D) || ParentDC->isFunctionOrMethod()) {
770 // D is a local of some kind. Look into the map of local
771 // declarations to their instantiations.
772 return cast<NamedDecl>(CurrentInstantiationScope->getInstantiationOf(D));
773 }
Douglas Gregor815215d2009-05-27 05:35:12 +0000774
Douglas Gregor2bba76b2009-05-27 17:07:49 +0000775 if (NamedDecl *ParentDecl = dyn_cast<NamedDecl>(ParentDC)) {
Douglas Gregored961e72009-05-27 17:54:46 +0000776 ParentDecl = InstantiateCurrentDeclRef(ParentDecl);
Douglas Gregor815215d2009-05-27 05:35:12 +0000777 if (!ParentDecl)
778 return 0;
779
780 ParentDC = cast<DeclContext>(ParentDecl);
781 }
782
Douglas Gregor815215d2009-05-27 05:35:12 +0000783 if (ParentDC != D->getDeclContext()) {
784 // We performed some kind of instantiation in the parent context,
785 // so now we need to look into the instantiated parent context to
786 // find the instantiation of the declaration D.
787 NamedDecl *Result = 0;
788 if (D->getDeclName()) {
789 DeclContext::lookup_result Found
790 = ParentDC->lookup(Context, D->getDeclName());
791 Result = findInstantiationOf(Context, D, Found.first, Found.second);
792 } else {
793 // Since we don't have a name for the entity we're looking for,
794 // our only option is to walk through all of the declarations to
795 // find that name. This will occur in a few cases:
796 //
797 // - anonymous struct/union within a template
798 // - unnamed class/struct/union/enum within a template
799 //
800 // FIXME: Find a better way to find these instantiations!
801 Result = findInstantiationOf(Context, D,
802 ParentDC->decls_begin(Context),
803 ParentDC->decls_end(Context));
804 }
805 assert(Result && "Unable to find instantiation of declaration!");
806 D = Result;
807 }
808
Douglas Gregor815215d2009-05-27 05:35:12 +0000809 if (CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(D))
Douglas Gregored961e72009-05-27 17:54:46 +0000810 if (ClassTemplateDecl *ClassTemplate
811 = Record->getDescribedClassTemplate()) {
812 // When the declaration D was parsed, it referred to the current
813 // instantiation. Therefore, look through the current context,
814 // which contains actual instantiations, to find the
815 // instantiation of the "current instantiation" that D refers
816 // to. Alternatively, we could just instantiate the
817 // injected-class-name with the current template arguments, but
818 // such an instantiation is far more expensive.
819 for (DeclContext *DC = CurContext; !DC->isFileContext();
820 DC = DC->getParent()) {
821 if (ClassTemplateSpecializationDecl *Spec
822 = dyn_cast<ClassTemplateSpecializationDecl>(DC))
823 if (Context.getCanonicalDecl(Spec->getSpecializedTemplate())
824 == Context.getCanonicalDecl(ClassTemplate))
825 return Spec;
826 }
827
828 assert(false &&
829 "Unable to find declaration for the current instantiation");
Douglas Gregor815215d2009-05-27 05:35:12 +0000830 }
831
832 return D;
833}
Douglas Gregord7f37bf2009-06-22 23:06:13 +0000834
835/// \brief Performs template instantiation for all implicit template
836/// instantiations we have seen until this point.
837void Sema::PerformPendingImplicitInstantiations() {
838 while (!PendingImplicitInstantiations.empty()) {
839 PendingImplicitInstantiation Inst = PendingImplicitInstantiations.front();
840 PendingImplicitInstantiations.pop();
841
842 if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Inst.first))
843 if (!Function->getBody(Context))
844 InstantiateFunctionDefinition(/*FIXME:*/Inst.second, Function);
845
846 // FIXME: instantiation static member variables
847 }
848}