[cfe-commits] r106860 - in /cfe/trunk: include/clang/AST/DeclTemplate.h lib/Frontend/PCHReaderDecl.cpp lib/Frontend/PCHWriterDecl.cpp test/PCH/cxx-templates.cpp test/PCH/cxx-templates.h
Argyrios Kyrtzidis
akyrtzi at gmail.com
Fri Jun 25 09:25:09 PDT 2010
Author: akirtzidis
Date: Fri Jun 25 11:25:09 2010
New Revision: 106860
URL: http://llvm.org/viewvc/llvm-project?rev=106860&view=rev
Log:
Support NonTypeTemplateParmDecl for PCH.
Modified:
cfe/trunk/include/clang/AST/DeclTemplate.h
cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
cfe/trunk/test/PCH/cxx-templates.cpp
cfe/trunk/test/PCH/cxx-templates.h
Modified: cfe/trunk/include/clang/AST/DeclTemplate.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclTemplate.h?rev=106860&r1=106859&r2=106860&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
+++ cfe/trunk/include/clang/AST/DeclTemplate.h Fri Jun 25 11:25:09 2010
@@ -660,9 +660,11 @@
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 @@
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
Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=106860&r1=106859&r2=106860&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Fri Jun 25 11:25:09 2010
@@ -851,7 +851,16 @@
}
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 @@
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");
Modified: cfe/trunk/lib/Frontend/PCHWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriterDecl.cpp?rev=106860&r1=106859&r2=106860&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriterDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriterDecl.cpp Fri Jun 25 11:25:09 2010
@@ -815,7 +815,17 @@
}
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) {
Modified: cfe/trunk/test/PCH/cxx-templates.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/cxx-templates.cpp?rev=106860&r1=106859&r2=106860&view=diff
==============================================================================
--- cfe/trunk/test/PCH/cxx-templates.cpp (original)
+++ cfe/trunk/test/PCH/cxx-templates.cpp Fri Jun 25 11:25:09 2010
@@ -13,7 +13,7 @@
};
void test() {
- int x = templ_f(3);
+ int x = templ_f<int, 5>(3);
S<char, float>::templ();
S<int, char>::partial();
Modified: cfe/trunk/test/PCH/cxx-templates.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/cxx-templates.h?rev=106860&r1=106859&r2=106860&view=diff
==============================================================================
--- cfe/trunk/test/PCH/cxx-templates.h (original)
+++ cfe/trunk/test/PCH/cxx-templates.h Fri Jun 25 11:25:09 2010
@@ -15,9 +15,9 @@
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);
More information about the cfe-commits
mailing list