зеркало из https://github.com/microsoft/clang-1.git
PCH support for declaration statements, and a test for PredefinedExpr
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69356 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
0de9d8857b
Коммит
84f2170062
|
@ -244,6 +244,9 @@ public:
|
||||||
SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),
|
SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),
|
||||||
StartLoc(startLoc), EndLoc(endLoc) {}
|
StartLoc(startLoc), EndLoc(endLoc) {}
|
||||||
|
|
||||||
|
/// \brief Build an empty declaration statement.
|
||||||
|
explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { }
|
||||||
|
|
||||||
virtual void Destroy(ASTContext& Ctx);
|
virtual void Destroy(ASTContext& Ctx);
|
||||||
|
|
||||||
/// isSingleDecl - This method returns true if this DeclStmt refers
|
/// isSingleDecl - This method returns true if this DeclStmt refers
|
||||||
|
@ -257,10 +260,13 @@ public:
|
||||||
|
|
||||||
const DeclGroupRef getDeclGroup() const { return DG; }
|
const DeclGroupRef getDeclGroup() const { return DG; }
|
||||||
DeclGroupRef getDeclGroup() { return DG; }
|
DeclGroupRef getDeclGroup() { return DG; }
|
||||||
|
void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
|
||||||
|
|
||||||
SourceLocation getStartLoc() const { return StartLoc; }
|
SourceLocation getStartLoc() const { return StartLoc; }
|
||||||
|
void setStartLoc(SourceLocation L) { StartLoc = L; }
|
||||||
SourceLocation getEndLoc() const { return EndLoc; }
|
SourceLocation getEndLoc() const { return EndLoc; }
|
||||||
|
void setEndLoc(SourceLocation L) { EndLoc = L; }
|
||||||
|
|
||||||
SourceRange getSourceRange() const {
|
SourceRange getSourceRange() const {
|
||||||
return SourceRange(StartLoc, EndLoc);
|
return SourceRange(StartLoc, EndLoc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -399,6 +399,8 @@ namespace clang {
|
||||||
STMT_BREAK,
|
STMT_BREAK,
|
||||||
/// \brief A ReturnStmt record.
|
/// \brief A ReturnStmt record.
|
||||||
STMT_RETURN,
|
STMT_RETURN,
|
||||||
|
/// \brief A DeclStmt record.
|
||||||
|
STMT_DECL,
|
||||||
/// \brief A PredefinedExpr record.
|
/// \brief A PredefinedExpr record.
|
||||||
EXPR_PREDEFINED,
|
EXPR_PREDEFINED,
|
||||||
/// \brief A DeclRefExpr record.
|
/// \brief A DeclRefExpr record.
|
||||||
|
|
|
@ -257,6 +257,7 @@ namespace {
|
||||||
unsigned VisitContinueStmt(ContinueStmt *S);
|
unsigned VisitContinueStmt(ContinueStmt *S);
|
||||||
unsigned VisitBreakStmt(BreakStmt *S);
|
unsigned VisitBreakStmt(BreakStmt *S);
|
||||||
unsigned VisitReturnStmt(ReturnStmt *S);
|
unsigned VisitReturnStmt(ReturnStmt *S);
|
||||||
|
unsigned VisitDeclStmt(DeclStmt *S);
|
||||||
unsigned VisitExpr(Expr *E);
|
unsigned VisitExpr(Expr *E);
|
||||||
unsigned VisitPredefinedExpr(PredefinedExpr *E);
|
unsigned VisitPredefinedExpr(PredefinedExpr *E);
|
||||||
unsigned VisitDeclRefExpr(DeclRefExpr *E);
|
unsigned VisitDeclRefExpr(DeclRefExpr *E);
|
||||||
|
@ -406,6 +407,25 @@ unsigned PCHStmtReader::VisitReturnStmt(ReturnStmt *S) {
|
||||||
return 1;
|
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) {
|
unsigned PCHStmtReader::VisitExpr(Expr *E) {
|
||||||
VisitStmt(E);
|
VisitStmt(E);
|
||||||
E->setType(Reader.GetType(Record[Idx++]));
|
E->setType(Reader.GetType(Record[Idx++]));
|
||||||
|
@ -2184,8 +2204,11 @@ Stmt *PCHReader::ReadStmt() {
|
||||||
S = new (Context) ReturnStmt(Empty);
|
S = new (Context) ReturnStmt(Empty);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case pch::STMT_DECL:
|
||||||
|
S = new (Context) DeclStmt(Empty);
|
||||||
|
break;
|
||||||
|
|
||||||
case pch::EXPR_PREDEFINED:
|
case pch::EXPR_PREDEFINED:
|
||||||
// FIXME: untested (until we can serialize function bodies).
|
|
||||||
S = new (Context) PredefinedExpr(Empty);
|
S = new (Context) PredefinedExpr(Empty);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -459,6 +459,7 @@ namespace {
|
||||||
void VisitContinueStmt(ContinueStmt *S);
|
void VisitContinueStmt(ContinueStmt *S);
|
||||||
void VisitBreakStmt(BreakStmt *S);
|
void VisitBreakStmt(BreakStmt *S);
|
||||||
void VisitReturnStmt(ReturnStmt *S);
|
void VisitReturnStmt(ReturnStmt *S);
|
||||||
|
void VisitDeclStmt(DeclStmt *S);
|
||||||
void VisitExpr(Expr *E);
|
void VisitExpr(Expr *E);
|
||||||
void VisitPredefinedExpr(PredefinedExpr *E);
|
void VisitPredefinedExpr(PredefinedExpr *E);
|
||||||
void VisitDeclRefExpr(DeclRefExpr *E);
|
void VisitDeclRefExpr(DeclRefExpr *E);
|
||||||
|
@ -600,6 +601,16 @@ void PCHStmtWriter::VisitReturnStmt(ReturnStmt *S) {
|
||||||
Code = pch::STMT_RETURN;
|
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) {
|
void PCHStmtWriter::VisitExpr(Expr *E) {
|
||||||
VisitStmt(E);
|
VisitStmt(E);
|
||||||
Writer.AddTypeRef(E->getType(), Record);
|
Writer.AddTypeRef(E->getType(), Record);
|
||||||
|
|
|
@ -7,3 +7,4 @@
|
||||||
|
|
||||||
void g0(void) { f0(5); }
|
void g0(void) { f0(5); }
|
||||||
int g1(int x) { return f1(x); }
|
int g1(int x) { return f1(x); }
|
||||||
|
const char* query_name(void) { return what_is_my_name(); }
|
||||||
|
|
|
@ -39,10 +39,12 @@ void f0(int x) {
|
||||||
x++;
|
x++;
|
||||||
} while (x < 10);
|
} while (x < 10);
|
||||||
|
|
||||||
for (; x < 20; ++x) {
|
for (int y = x; y < 20; ++y) {
|
||||||
if (x == 12)
|
if (x + y == 12)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int z = x, *y, j = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
int f1(int x) {
|
int f1(int x) {
|
||||||
|
@ -56,3 +58,5 @@ int f1(int x) {
|
||||||
|
|
||||||
return x*2;
|
return x*2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* what_is_my_name(void) { return __func__; }
|
||||||
|
|
Загрузка…
Ссылка в новой задаче