From eb7f96141f754150a92433286fa385910a22f494 Mon Sep 17 00:00:00 2001 From: Sam Weinig Date: Sun, 7 Feb 2010 06:32:43 +0000 Subject: [PATCH] Roll r95513 back in. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95515 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/ExprCXX.h | 13 +++++++++++++ include/clang/Frontend/PCHBitCodes.h | 6 +++++- lib/Frontend/PCHReaderStmt.cpp | 21 +++++++++++++++++++++ lib/Frontend/PCHWriter.cpp | 9 +++++++++ lib/Frontend/PCHWriterStmt.cpp | 15 +++++++++++++++ test/PCH/cxx_exprs.cpp | 15 ++++++++++++--- test/PCH/cxx_exprs.h | 18 +++++++++++++----- 7 files changed, 88 insertions(+), 9 deletions(-) diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index 76ef02df4b..6567b14d6c 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -241,10 +241,17 @@ public: CXXBoolLiteralExpr(bool val, QualType Ty, SourceLocation l) : Expr(CXXBoolLiteralExprClass, Ty, false, false), Value(val), Loc(l) {} + explicit CXXBoolLiteralExpr(EmptyShell Empty) + : Expr(CXXBoolLiteralExprClass, Empty) { } + bool getValue() const { return Value; } + void setValue(bool V) { Value = V; } virtual SourceRange getSourceRange() const { return SourceRange(Loc); } + SourceLocation getLocation() const { return Loc; } + void setLocation(SourceLocation L) { Loc = L; } + static bool classof(const Stmt *T) { return T->getStmtClass() == CXXBoolLiteralExprClass; } @@ -262,8 +269,14 @@ public: CXXNullPtrLiteralExpr(QualType Ty, SourceLocation l) : Expr(CXXNullPtrLiteralExprClass, Ty, false, false), Loc(l) {} + explicit CXXNullPtrLiteralExpr(EmptyShell Empty) + : Expr(CXXNullPtrLiteralExprClass, Empty) { } + virtual SourceRange getSourceRange() const { return SourceRange(Loc); } + SourceLocation getLocation() const { return Loc; } + void setLocation(SourceLocation L) { Loc = L; } + static bool classof(const Stmt *T) { return T->getStmtClass() == CXXNullPtrLiteralExprClass; } diff --git a/include/clang/Frontend/PCHBitCodes.h b/include/clang/Frontend/PCHBitCodes.h index 1a9f4ceab9..578ce2a9e1 100644 --- a/include/clang/Frontend/PCHBitCodes.h +++ b/include/clang/Frontend/PCHBitCodes.h @@ -686,7 +686,11 @@ namespace clang { // \brief A CXXConstCastExpr record. EXPR_CXX_CONST_CAST, // \brief A CXXFunctionalCastExpr record. - EXPR_CXX_FUNCTIONAL_CAST + EXPR_CXX_FUNCTIONAL_CAST, + // \brief A CXXBoolLiteralExpr record. + EXPR_CXX_BOOL_LITERAL, + // \brief A CXXNullPtrLiteralExpr record. + EXPR_CXX_NULL_PTR_LITERAL }; /// \brief The kinds of designators that can occur in a diff --git a/lib/Frontend/PCHReaderStmt.cpp b/lib/Frontend/PCHReaderStmt.cpp index aa80b362a5..d123694d69 100644 --- a/lib/Frontend/PCHReaderStmt.cpp +++ b/lib/Frontend/PCHReaderStmt.cpp @@ -123,6 +123,8 @@ namespace { unsigned VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E); unsigned VisitCXXConstCastExpr(CXXConstCastExpr *E); unsigned VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E); + unsigned VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); + unsigned VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); }; } @@ -906,6 +908,19 @@ unsigned PCHStmtReader::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) { return num; } +unsigned PCHStmtReader::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { + VisitExpr(E); + E->setValue(Record[Idx++]); + E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); + return 0; +} + +unsigned PCHStmtReader::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { + VisitExpr(E); + E->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++])); + return 0; +} + // Within the bitstream, expressions are stored in Reverse Polish // Notation, with each of the subexpressions preceding the // expression they are stored in. To evaluate expressions, we @@ -1235,7 +1250,13 @@ Stmt *PCHReader::ReadStmt(llvm::BitstreamCursor &Cursor) { S = new (Context) CXXFunctionalCastExpr(Empty); break; + case pch::EXPR_CXX_BOOL_LITERAL: + S = new (Context) CXXBoolLiteralExpr(Empty); + break; + case pch::EXPR_CXX_NULL_PTR_LITERAL: + S = new (Context) CXXNullPtrLiteralExpr(Empty); + break; } // We hit a STMT_STOP, so we're done with this expression. diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp index a87b8cde2c..5085cf43d0 100644 --- a/lib/Frontend/PCHWriter.cpp +++ b/lib/Frontend/PCHWriter.cpp @@ -513,6 +513,15 @@ static void AddStmtsExprs(llvm::BitstreamWriter &Stream, RECORD(STMT_OBJC_AT_TRY); RECORD(STMT_OBJC_AT_SYNCHRONIZED); RECORD(STMT_OBJC_AT_THROW); + RECORD(EXPR_CXX_OPERATOR_CALL); + RECORD(EXPR_CXX_CONSTRUCT); + RECORD(EXPR_CXX_STATIC_CAST); + RECORD(EXPR_CXX_DYNAMIC_CAST); + RECORD(EXPR_CXX_REINTERPRET_CAST); + RECORD(EXPR_CXX_CONST_CAST); + RECORD(EXPR_CXX_FUNCTIONAL_CAST); + RECORD(EXPR_CXX_BOOL_LITERAL); + RECORD(EXPR_CXX_NULL_PTR_LITERAL); #undef RECORD } diff --git a/lib/Frontend/PCHWriterStmt.cpp b/lib/Frontend/PCHWriterStmt.cpp index 13ca8cdd9f..a8cc9d6f45 100644 --- a/lib/Frontend/PCHWriterStmt.cpp +++ b/lib/Frontend/PCHWriterStmt.cpp @@ -118,6 +118,8 @@ namespace { void VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E); void VisitCXXConstCastExpr(CXXConstCastExpr *E); void VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E); + void VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E); + void VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E); }; } @@ -834,6 +836,19 @@ void PCHStmtWriter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) { Code = pch::EXPR_CXX_FUNCTIONAL_CAST; } +void PCHStmtWriter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { + VisitExpr(E); + Record.push_back(E->getValue()); + Writer.AddSourceLocation(E->getLocation(), Record); + Code = pch::EXPR_CXX_BOOL_LITERAL; +} + +void PCHStmtWriter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E) { + VisitExpr(E); + Writer.AddSourceLocation(E->getLocation(), Record); + Code = pch::EXPR_CXX_NULL_PTR_LITERAL; +} + //===----------------------------------------------------------------------===// // PCHWriter Implementation //===----------------------------------------------------------------------===// diff --git a/test/PCH/cxx_exprs.cpp b/test/PCH/cxx_exprs.cpp index 51269d57b1..0f0fe88dc5 100644 --- a/test/PCH/cxx_exprs.cpp +++ b/test/PCH/cxx_exprs.cpp @@ -1,13 +1,14 @@ // Test this without pch. -// RUN: %clang_cc1 -include %S/cxx_exprs.h -fsyntax-only -verify %s +// RUN: %clang_cc1 -include %S/cxx_exprs.h -std=c++0x -fsyntax-only -verify %s // Test with pch. -// RUN: %clang_cc1 -x c++-header -emit-pch -o %t %S/cxx_exprs.h -// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s +// RUN: %clang_cc1 -x c++-header -std=c++0x -emit-pch -o %t %S/cxx_exprs.h +// RUN: %clang_cc1 -std=c++0x -include-pch %t -fsyntax-only -verify %s int integer; double floating; char character; +bool boolean; // CXXStaticCastExpr static_cast_result void_ptr = &integer; @@ -24,3 +25,11 @@ const_cast_result char_ptr = &character; // CXXFunctionalCastExpr functional_cast_result *double_ptr = &floating; + +// CXXBoolLiteralExpr +bool_literal_result *bool_ptr = &boolean; +static_assert(true_value, "true_value is true"); +static_assert(!false_value, "false_value is false"); + +// CXXNullPtrLiteralExpr +cxx_null_ptr_result null_ptr = nullptr; diff --git a/test/PCH/cxx_exprs.h b/test/PCH/cxx_exprs.h index b649428494..a871aa201f 100644 --- a/test/PCH/cxx_exprs.h +++ b/test/PCH/cxx_exprs.h @@ -1,21 +1,29 @@ // Header for PCH test cxx_exprs.cpp // CXXStaticCastExpr -typedef typeof(static_cast(0)) static_cast_result; +typedef __typeof__(static_cast(0)) static_cast_result; // CXXDynamicCastExpr struct Base { virtual void f(); }; struct Derived : Base { }; Base *base_ptr; -typedef typeof(dynamic_cast(base_ptr)) dynamic_cast_result; +typedef __typeof__(dynamic_cast(base_ptr)) dynamic_cast_result; // CXXReinterpretCastExpr -typedef typeof(reinterpret_cast(0)) reinterpret_cast_result; +typedef __typeof__(reinterpret_cast(0)) reinterpret_cast_result; // CXXConstCastExpr const char *const_char_ptr_value; -typedef typeof(const_cast(const_char_ptr_value)) const_cast_result; +typedef __typeof__(const_cast(const_char_ptr_value)) const_cast_result; // CXXFunctionalCastExpr int int_value; -typedef typeof(double(int_value)) functional_cast_result; +typedef __typeof__(double(int_value)) functional_cast_result; + +// CXXBoolLiteralExpr +typedef __typeof__(true) bool_literal_result; +const bool true_value = true; +const bool false_value = false; + +// CXXNullPtrLiteralExpr +typedef __typeof__(nullptr) cxx_null_ptr_result; -- 2.40.0