From 95fc98ce95d4faa4f1bb2783384150530404ea6f Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Tue, 22 Jun 2010 17:07:59 +0000 Subject: [PATCH] Read/write CXXDeleteExpr from/to PCH. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106552 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/ExprCXX.h | 8 ++++++++ include/clang/Frontend/PCHBitCodes.h | 1 + lib/Frontend/PCHReaderStmt.cpp | 14 ++++++++++++++ lib/Frontend/PCHWriterStmt.cpp | 11 +++++++++++ test/PCH/cxx_exprs.h | 4 ++-- 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index 0c493f36df..c7f4ff6288 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -1082,18 +1082,26 @@ public: : Expr(CXXDeleteExprClass, ty, false, false), GlobalDelete(globalDelete), ArrayForm(arrayForm), OperatorDelete(operatorDelete), Argument(arg), Loc(loc) { } + explicit CXXDeleteExpr(EmptyShell Shell) + : Expr(CXXDeleteExprClass, Shell), OperatorDelete(0), Argument(0) { } bool isGlobalDelete() const { return GlobalDelete; } bool isArrayForm() const { return ArrayForm; } + + void setGlobalDelete(bool V) { GlobalDelete = V; } + void setArrayForm(bool V) { ArrayForm = V; } FunctionDecl *getOperatorDelete() const { return OperatorDelete; } + void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; } Expr *getArgument() { return cast(Argument); } const Expr *getArgument() const { return cast(Argument); } + void setArgument(Expr *E) { Argument = E; } virtual SourceRange getSourceRange() const { return SourceRange(Loc, Argument->getLocEnd()); } + void setStartLoc(SourceLocation L) { Loc = L; } static bool classof(const Stmt *T) { return T->getStmtClass() == CXXDeleteExprClass; diff --git a/include/clang/Frontend/PCHBitCodes.h b/include/clang/Frontend/PCHBitCodes.h index 4e1320188a..b95d0d99ae 100644 --- a/include/clang/Frontend/PCHBitCodes.h +++ b/include/clang/Frontend/PCHBitCodes.h @@ -763,6 +763,7 @@ namespace clang { // EXPR_CXX_ZERO_INIT_VALUE, // CXXZeroInitValueExpr EXPR_CXX_NEW, // CXXNewExpr + EXPR_CXX_DELETE, // CXXDeleteExpr EXPR_CXX_EXPR_WITH_TEMPORARIES // CXXExprWithTemporaries }; diff --git a/lib/Frontend/PCHReaderStmt.cpp b/lib/Frontend/PCHReaderStmt.cpp index fd3cde43fa..4a38a36367 100644 --- a/lib/Frontend/PCHReaderStmt.cpp +++ b/lib/Frontend/PCHReaderStmt.cpp @@ -134,6 +134,7 @@ namespace { unsigned VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E); unsigned VisitCXXNewExpr(CXXNewExpr *E); + unsigned VisitCXXDeleteExpr(CXXDeleteExpr *E); unsigned VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E); }; @@ -1087,6 +1088,16 @@ unsigned PCHStmtReader::VisitCXXNewExpr(CXXNewExpr *E) { return TotalSubExprs; } +unsigned PCHStmtReader::VisitCXXDeleteExpr(CXXDeleteExpr *E) { + VisitExpr(E); + E->setGlobalDelete(Record[Idx++]); + E->setArrayForm(Record[Idx++]); + E->setOperatorDelete( + cast_or_null(Reader.GetDecl(Record[Idx++]))); + E->setArgument(cast_or_null(StmtStack.back())); + E->setStartLoc(SourceLocation::getFromRawEncoding(Record[Idx++])); + return 1; +} unsigned PCHStmtReader::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E) { VisitExpr(E); @@ -1475,6 +1486,9 @@ Stmt *PCHReader::ReadStmt(llvm::BitstreamCursor &Cursor) { case pch::EXPR_CXX_NEW: S = new (Context) CXXNewExpr(Empty); break; + case pch::EXPR_CXX_DELETE: + S = new (Context) CXXDeleteExpr(Empty); + break; case pch::EXPR_CXX_EXPR_WITH_TEMPORARIES: diff --git a/lib/Frontend/PCHWriterStmt.cpp b/lib/Frontend/PCHWriterStmt.cpp index b3501d0984..eb95eba584 100644 --- a/lib/Frontend/PCHWriterStmt.cpp +++ b/lib/Frontend/PCHWriterStmt.cpp @@ -130,6 +130,7 @@ namespace { void VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E); void VisitCXXNewExpr(CXXNewExpr *E); + void VisitCXXDeleteExpr(CXXDeleteExpr *E); void VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E); }; @@ -997,6 +998,16 @@ void PCHStmtWriter::VisitCXXNewExpr(CXXNewExpr *E) { Code = pch::EXPR_CXX_NEW; } +void PCHStmtWriter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { + VisitExpr(E); + Record.push_back(E->isGlobalDelete()); + Record.push_back(E->isArrayForm()); + Writer.AddDeclRef(E->getOperatorDelete(), Record); + Writer.WriteSubStmt(E->getArgument()); + Writer.AddSourceLocation(E->getSourceRange().getBegin(), Record); + + Code = pch::EXPR_CXX_DELETE; +} void PCHStmtWriter::VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E) { VisitExpr(E); diff --git a/test/PCH/cxx_exprs.h b/test/PCH/cxx_exprs.h index f647922389..67ab4a6d34 100644 --- a/test/PCH/cxx_exprs.h +++ b/test/PCH/cxx_exprs.h @@ -68,8 +68,8 @@ void Derived::g() { int A = int(0.5); // CXXFunctionalCastExpr A = int(); // CXXZeroInitValueExpr - new Base(4); // CXXNewExpr - + Base *b = new Base(4); // CXXNewExpr + delete b; // CXXDeleteExpr } -- 2.40.0