aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-06-25 16:25:09 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2010-06-25 16:25:09 +0000
commitb24e199fbd17af780ab000c5862d191e4daffc0f (patch)
tree38fa1c7bc5778b722be9dce31005dcea593f4e9d
parentc4117aae93de65206fec2c82db82ee060b6fbe88 (diff)
Support NonTypeTemplateParmDecl for PCH.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106860 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/DeclTemplate.h4
-rw-r--r--lib/Frontend/PCHReaderDecl.cpp14
-rw-r--r--lib/Frontend/PCHWriterDecl.cpp12
-rw-r--r--test/PCH/cxx-templates.cpp2
-rw-r--r--test/PCH/cxx-templates.h4
5 files changed, 30 insertions, 6 deletions
diff --git a/include/clang/AST/DeclTemplate.h b/include/clang/AST/DeclTemplate.h
index ed4d54a1dd..05bad9303d 100644
--- a/include/clang/AST/DeclTemplate.h
+++ b/include/clang/AST/DeclTemplate.h
@@ -660,9 +660,11 @@ protected:
public:
/// Get the nesting depth of the template parameter.
unsigned getDepth() const { return Depth; }
+ void setDepth(unsigned D) { Depth = D; }
/// Get the position of the template parameter within its parameter list.
unsigned getPosition() const { return Position; }
+ void setPosition(unsigned P) { Position = P; }
/// Get the index of the template parameter within its parameter list.
unsigned getIndex() const { return Position; }
@@ -785,7 +787,9 @@ public:
unsigned P, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo);
using TemplateParmPosition::getDepth;
+ using TemplateParmPosition::setDepth;
using TemplateParmPosition::getPosition;
+ using TemplateParmPosition::setPosition;
using TemplateParmPosition::getIndex;
/// \brief Determine whether this template parameter has a default
diff --git a/lib/Frontend/PCHReaderDecl.cpp b/lib/Frontend/PCHReaderDecl.cpp
index 1877a2199d..028c563a07 100644
--- a/lib/Frontend/PCHReaderDecl.cpp
+++ b/lib/Frontend/PCHReaderDecl.cpp
@@ -851,7 +851,16 @@ void PCHDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
}
void PCHDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
- assert(false && "cannot read NonTypeTemplateParmDecl");
+ VisitVarDecl(D);
+ // TemplateParmPosition.
+ D->setDepth(Record[Idx++]);
+ D->setPosition(Record[Idx++]);
+ // Rest of NonTypeTemplateParmDecl.
+ if (Record[Idx++]) {
+ Expr *DefArg = Reader.ReadDeclExpr();
+ bool Inherited = Record[Idx++];
+ D->setDefaultArgument(DefArg, Inherited);
+ }
}
void PCHDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
@@ -1212,7 +1221,8 @@ Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
D = TemplateTypeParmDecl::Create(*Context, 0, SourceLocation(), 0,0,0,0,0);
break;
case pch::DECL_NON_TYPE_TEMPLATE_PARM:
- assert(false && "cannot read NonTypeTemplateParmDecl");
+ D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(), 0,0,0,
+ QualType(),0);
break;
case pch::DECL_TEMPLATE_TEMPLATE_PARM:
assert(false && "cannot read TemplateTemplateParmDecl");
diff --git a/lib/Frontend/PCHWriterDecl.cpp b/lib/Frontend/PCHWriterDecl.cpp
index d505caff96..36a1848d2a 100644
--- a/lib/Frontend/PCHWriterDecl.cpp
+++ b/lib/Frontend/PCHWriterDecl.cpp
@@ -815,7 +815,17 @@ void PCHDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
}
void PCHDeclWriter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
- assert(false && "cannot write NonTypeTemplateParmDecl");
+ VisitVarDecl(D);
+ // TemplateParmPosition.
+ Record.push_back(D->getDepth());
+ Record.push_back(D->getPosition());
+ // Rest of NonTypeTemplateParmDecl.
+ Record.push_back(D->getDefaultArgument() != 0);
+ if (D->getDefaultArgument()) {
+ Writer.AddStmt(D->getDefaultArgument());
+ Record.push_back(D->defaultArgumentWasInherited());
+ }
+ Code = pch::DECL_NON_TYPE_TEMPLATE_PARM;
}
void PCHDeclWriter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
diff --git a/test/PCH/cxx-templates.cpp b/test/PCH/cxx-templates.cpp
index cfddde52b3..f12742755a 100644
--- a/test/PCH/cxx-templates.cpp
+++ b/test/PCH/cxx-templates.cpp
@@ -13,7 +13,7 @@ struct A {
};
void test() {
- int x = templ_f(3);
+ int x = templ_f<int, 5>(3);
S<char, float>::templ();
S<int, char>::partial();
diff --git a/test/PCH/cxx-templates.h b/test/PCH/cxx-templates.h
index b17b355db5..840850d813 100644
--- a/test/PCH/cxx-templates.h
+++ b/test/PCH/cxx-templates.h
@@ -15,9 +15,9 @@ struct S<int, float> {
static void explicit_special();
};
-template <typename T>
+template <typename T, int y>
T templ_f(T x) {
- return x;
+ return x+y;
}
void govl(int);