aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend/PCHWriter.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-04-14 23:32:43 +0000
committerDouglas Gregor <dgregor@apple.com>2009-04-14 23:32:43 +0000
commit087fd536809ebe754d91c641a98917e02dd7452d (patch)
tree6c14622a32eb48b850576d7705628c7a3f078f4a /lib/Frontend/PCHWriter.cpp
parent5717daef564a1071c34549150e7333025ea46fa2 (diff)
Add PCH support for ImplicitCastExprs. This is the first expression
kind PCH handles that has an expression as an operand, so most of this work is in the infrastructure to rebuild expression trees from the serialized representation. We now store expressions in post-order (e.g., Reverse Polish Notation), so that we can easily rebuild the appropriate expression tree. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69101 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/PCHWriter.cpp')
-rw-r--r--lib/Frontend/PCHWriter.cpp48
1 files changed, 44 insertions, 4 deletions
diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp
index 20aee9c441..4ca3c8d0ae 100644
--- a/lib/Frontend/PCHWriter.cpp
+++ b/lib/Frontend/PCHWriter.cpp
@@ -449,6 +449,8 @@ namespace {
void VisitIntegerLiteral(IntegerLiteral *E);
void VisitFloatingLiteral(FloatingLiteral *E);
void VisitCharacterLiteral(CharacterLiteral *E);
+ void VisitCastExpr(CastExpr *E);
+ void VisitImplicitCastExpr(ImplicitCastExpr *E);
};
}
@@ -495,6 +497,17 @@ void PCHStmtWriter::VisitCharacterLiteral(CharacterLiteral *E) {
Code = pch::EXPR_CHARACTER_LITERAL;
}
+void PCHStmtWriter::VisitCastExpr(CastExpr *E) {
+ VisitExpr(E);
+ Writer.WriteSubExpr(E->getSubExpr());
+}
+
+void PCHStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
+ VisitCastExpr(E);
+ Record.push_back(E->isLvalueCast());
+ Code = pch::EXPR_IMPLICIT_CAST;
+}
+
//===----------------------------------------------------------------------===//
// PCHWriter Implementation
//===----------------------------------------------------------------------===//
@@ -1245,16 +1258,32 @@ void PCHWriter::AddDeclarationName(DeclarationName Name, RecordData &Record) {
}
}
+/// \brief Write the given subexpression to the bitstream.
+void PCHWriter::WriteSubExpr(Expr *E) {
+ RecordData Record;
+ PCHStmtWriter Writer(*this, Record);
+
+ if (!E) {
+ S.EmitRecord(pch::EXPR_NULL, Record);
+ return;
+ }
+
+ Writer.Code = pch::EXPR_NULL;
+ Writer.Visit(E);
+ assert(Writer.Code != pch::EXPR_NULL &&
+ "Unhandled expression writing PCH file");
+ S.EmitRecord(Writer.Code, Record);
+}
+
/// \brief Flush all of the expressions that have been added to the
/// queue via AddExpr().
void PCHWriter::FlushExprs() {
RecordData Record;
PCHStmtWriter Writer(*this, Record);
- while (!ExprsToEmit.empty()) {
- Expr *E = ExprsToEmit.front();
- ExprsToEmit.pop();
- Record.clear();
+ for (unsigned I = 0, N = ExprsToEmit.size(); I != N; ++I) {
+ Expr *E = ExprsToEmit[I];
+
if (!E) {
S.EmitRecord(pch::EXPR_NULL, Record);
continue;
@@ -1265,5 +1294,16 @@ void PCHWriter::FlushExprs() {
assert(Writer.Code != pch::EXPR_NULL &&
"Unhandled expression writing PCH file");
S.EmitRecord(Writer.Code, Record);
+
+ assert(N == ExprsToEmit.size() &&
+ "Subexpression writen via AddExpr rather than WriteSubExpr!");
+
+ // Note that we are at the end of a full expression. Any
+ // expression records that follow this one are part of a different
+ // expression.
+ Record.clear();
+ S.EmitRecord(pch::EXPR_STOP, Record);
}
+
+ ExprsToEmit.clear();
}