PCH support for declaration statements, and a test for PredefinedExpr

llvm-svn: 69356
This commit is contained in:
Douglas Gregor 2009-04-17 16:55:36 +00:00
parent f961e5921f
commit 915b6c663d
6 changed files with 51 additions and 4 deletions

View File

@ -244,6 +244,9 @@ public:
SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),
StartLoc(startLoc), EndLoc(endLoc) {}
/// \brief Build an empty declaration statement.
explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { }
virtual void Destroy(ASTContext& Ctx);
/// isSingleDecl - This method returns true if this DeclStmt refers
@ -257,10 +260,13 @@ public:
const DeclGroupRef getDeclGroup() const { return DG; }
DeclGroupRef getDeclGroup() { return DG; }
void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
SourceLocation getStartLoc() const { return StartLoc; }
void setStartLoc(SourceLocation L) { StartLoc = L; }
SourceLocation getEndLoc() const { return EndLoc; }
void setEndLoc(SourceLocation L) { EndLoc = L; }
SourceRange getSourceRange() const {
return SourceRange(StartLoc, EndLoc);
}

View File

@ -399,6 +399,8 @@ namespace clang {
STMT_BREAK,
/// \brief A ReturnStmt record.
STMT_RETURN,
/// \brief A DeclStmt record.
STMT_DECL,
/// \brief A PredefinedExpr record.
EXPR_PREDEFINED,
/// \brief A DeclRefExpr record.

View File

@ -257,6 +257,7 @@ namespace {
unsigned VisitContinueStmt(ContinueStmt *S);
unsigned VisitBreakStmt(BreakStmt *S);
unsigned VisitReturnStmt(ReturnStmt *S);
unsigned VisitDeclStmt(DeclStmt *S);
unsigned VisitExpr(Expr *E);
unsigned VisitPredefinedExpr(PredefinedExpr *E);
unsigned VisitDeclRefExpr(DeclRefExpr *E);
@ -406,6 +407,25 @@ unsigned PCHStmtReader::VisitReturnStmt(ReturnStmt *S) {
return 1;
}
unsigned PCHStmtReader::VisitDeclStmt(DeclStmt *S) {
VisitStmt(S);
S->setStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
S->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
if (Idx + 1 == Record.size()) {
// Single declaration
S->setDeclGroup(DeclGroupRef(Reader.GetDecl(Record[Idx++])));
} else {
llvm::SmallVector<Decl *, 16> Decls;
Decls.reserve(Record.size() - Idx);
for (unsigned N = Record.size(); Idx != N; ++Idx)
Decls.push_back(Reader.GetDecl(Record[Idx]));
S->setDeclGroup(DeclGroupRef(DeclGroup::Create(Reader.getContext(),
&Decls[0], Decls.size())));
}
return 0;
}
unsigned PCHStmtReader::VisitExpr(Expr *E) {
VisitStmt(E);
E->setType(Reader.GetType(Record[Idx++]));
@ -2184,8 +2204,11 @@ Stmt *PCHReader::ReadStmt() {
S = new (Context) ReturnStmt(Empty);
break;
case pch::STMT_DECL:
S = new (Context) DeclStmt(Empty);
break;
case pch::EXPR_PREDEFINED:
// FIXME: untested (until we can serialize function bodies).
S = new (Context) PredefinedExpr(Empty);
break;

View File

@ -459,6 +459,7 @@ namespace {
void VisitContinueStmt(ContinueStmt *S);
void VisitBreakStmt(BreakStmt *S);
void VisitReturnStmt(ReturnStmt *S);
void VisitDeclStmt(DeclStmt *S);
void VisitExpr(Expr *E);
void VisitPredefinedExpr(PredefinedExpr *E);
void VisitDeclRefExpr(DeclRefExpr *E);
@ -600,6 +601,16 @@ void PCHStmtWriter::VisitReturnStmt(ReturnStmt *S) {
Code = pch::STMT_RETURN;
}
void PCHStmtWriter::VisitDeclStmt(DeclStmt *S) {
VisitStmt(S);
Writer.AddSourceLocation(S->getStartLoc(), Record);
Writer.AddSourceLocation(S->getEndLoc(), Record);
DeclGroupRef DG = S->getDeclGroup();
for (DeclGroupRef::iterator D = DG.begin(), DEnd = DG.end(); D != DEnd; ++D)
Writer.AddDeclRef(*D, Record);
Code = pch::STMT_DECL;
}
void PCHStmtWriter::VisitExpr(Expr *E) {
VisitStmt(E);
Writer.AddTypeRef(E->getType(), Record);

View File

@ -7,3 +7,4 @@
void g0(void) { f0(5); }
int g1(int x) { return f1(x); }
const char* query_name(void) { return what_is_my_name(); }

View File

@ -39,10 +39,12 @@ void f0(int x) {
x++;
} while (x < 10);
for (; x < 20; ++x) {
if (x == 12)
for (int y = x; y < 20; ++y) {
if (x + y == 12)
return;
}
int z = x, *y, j = 5;
}
int f1(int x) {
@ -56,3 +58,5 @@ int f1(int x) {
return x*2;
}
const char* what_is_my_name(void) { return __func__; }