summaryrefslogtreecommitdiffstats
path: root/clang/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
commitf0b575f79db133a7bcc373fb5480b9ab51514810 (patch)
tree4dd83f782404e2350d8dc9391c528ef2814f11b2 /clang/lib/Frontend/PCHWriter.cpp
parent9351c02befc53ac5ad60337b0bc3714d7bd4f3d6 (diff)
downloadbcm5719-llvm-f0b575f79db133a7bcc373fb5480b9ab51514810.tar.gz
bcm5719-llvm-f0b575f79db133a7bcc373fb5480b9ab51514810.zip
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. llvm-svn: 69101
Diffstat (limited to 'clang/lib/Frontend/PCHWriter.cpp')
-rw-r--r--clang/lib/Frontend/PCHWriter.cpp48
1 files changed, 44 insertions, 4 deletions
diff --git a/clang/lib/Frontend/PCHWriter.cpp b/clang/lib/Frontend/PCHWriter.cpp
index 20aee9c4419..4ca3c8d0ae6 100644
--- a/clang/lib/Frontend/PCHWriter.cpp
+++ b/clang/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();
}
OpenPOWER on IntegriCloud