[cfe-commits] r73176 - in /cfe/trunk/lib/Sema: Sema.h SemaTemplateInstantiate.cpp
Douglas Gregor
dgregor at apple.com
Wed Jun 10 17:06:25 PDT 2009
Author: dgregor
Date: Wed Jun 10 19:06:24 2009
New Revision: 73176
URL: http://llvm.org/viewvc/llvm-project?rev=73176&view=rev
Log:
Separate TemplateArgument instantiation logic into its own function. No functionality change.
Modified:
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=73176&r1=73175&r2=73176&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Wed Jun 10 19:06:24 2009
@@ -2307,6 +2307,8 @@
TemplateName
InstantiateTemplateName(TemplateName Name, SourceLocation Loc,
const TemplateArgumentList &TemplateArgs);
+ TemplateArgument Instantiate(TemplateArgument Arg,
+ const TemplateArgumentList &TemplateArgs);
void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
FunctionDecl *Function);
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=73176&r1=73175&r2=73176&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Wed Jun 10 19:06:24 2009
@@ -553,37 +553,11 @@
InstantiatedTemplateArgs.reserve(T->getNumArgs());
for (TemplateSpecializationType::iterator Arg = T->begin(), ArgEnd = T->end();
Arg != ArgEnd; ++Arg) {
- switch (Arg->getKind()) {
- case TemplateArgument::Null:
- assert(false && "Should never have a NULL template argument");
- break;
-
- case TemplateArgument::Type: {
- QualType T = SemaRef.InstantiateType(Arg->getAsType(),
- TemplateArgs,
- Arg->getLocation(),
- DeclarationName());
- if (T.isNull())
- return QualType();
-
- InstantiatedTemplateArgs.push_back(
- TemplateArgument(Arg->getLocation(), T));
- break;
- }
+ TemplateArgument InstArg = SemaRef.Instantiate(*Arg, TemplateArgs);
+ if (InstArg.isNull())
+ return QualType();
- case TemplateArgument::Declaration:
- case TemplateArgument::Integral:
- InstantiatedTemplateArgs.push_back(*Arg);
- break;
-
- case TemplateArgument::Expression:
- Sema::OwningExprResult E
- = SemaRef.InstantiateExpr(Arg->getAsExpr(), TemplateArgs);
- if (E.isInvalid())
- return QualType();
- InstantiatedTemplateArgs.push_back(E.takeAs<Expr>());
- break;
- }
+ InstantiatedTemplateArgs.push_back(InstArg);
}
// FIXME: We're missing the locations of the template name, '<', and '>'.
@@ -1097,3 +1071,38 @@
// Decl. However, this won't be needed until we implement member templates.
return Name;
}
+
+TemplateArgument Sema::Instantiate(TemplateArgument Arg,
+ const TemplateArgumentList &TemplateArgs) {
+ switch (Arg.getKind()) {
+ case TemplateArgument::Null:
+ assert(false && "Should never have a NULL template argument");
+ break;
+
+ case TemplateArgument::Type: {
+ QualType T = InstantiateType(Arg.getAsType(), TemplateArgs,
+ Arg.getLocation(), DeclarationName());
+ if (T.isNull())
+ return TemplateArgument();
+
+ return TemplateArgument(Arg.getLocation(), T);
+ }
+
+ case TemplateArgument::Declaration:
+ // FIXME: Template instantiation for template template parameters.
+ return Arg;
+
+ case TemplateArgument::Integral:
+ return Arg;
+
+ case TemplateArgument::Expression: {
+ Sema::OwningExprResult E = InstantiateExpr(Arg.getAsExpr(), TemplateArgs);
+ if (E.isInvalid())
+ return TemplateArgument();
+ return TemplateArgument(E.takeAs<Expr>());
+ }
+ }
+
+ assert(false && "Unhandled template argument kind");
+ return TemplateArgument();
+}
More information about the cfe-commits
mailing list