]> granicus.if.org Git - clang/commitdiff
Add PCH support for CXXBoolLiteralExpr and CXXNullPtrLiteralExpr.
authorSam Weinig <sam.weinig@gmail.com>
Sun, 7 Feb 2010 04:44:10 +0000 (04:44 +0000)
committerSam Weinig <sam.weinig@gmail.com>
Sun, 7 Feb 2010 04:44:10 +0000 (04:44 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95513 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ExprCXX.h
include/clang/Frontend/PCHBitCodes.h
lib/Frontend/PCHReaderStmt.cpp
lib/Frontend/PCHWriter.cpp
lib/Frontend/PCHWriterStmt.cpp
test/PCH/cxx_exprs.cpp
test/PCH/cxx_exprs.h

index 76ef02df4bedf06bfaf1998c797900d373b27f13..6567b14d6ce7bff4a5f6ad7f62186568271dcd17 100644 (file)
@@ -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;
   }
index 1a9f4ceab933e6b3b1f218be46bc4696ac8b10ee..578ce2a9e1b8831044821413321b4f8535cca2a0 100644 (file)
@@ -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
index aa80b362a5f9ef470d00d8db7abc1fe7fba5928c..d123694d699d8b302ff267d0fbab058397da8f3f 100644 (file)
@@ -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.
index a87b8cde2ca1cf026e4577e37332ebc268c6d1f2..5085cf43d023c9f01ab75a5ea626e7b07eaa4600 100644 (file)
@@ -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
 }
 
index 13ca8cdd9f5f9bcad958bbce6ba9b2bb29fb7635..a8cc9d6f459175405eb31ab2130f19e80e67591b 100644 (file)
@@ -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
 //===----------------------------------------------------------------------===//
index 51269d57b147a9e128052d378a89279f7699c971..0f0fe88dc54aa83a9509c05662699d89cbdfa5d6 100644 (file)
@@ -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;
index b6494284941912b55477701b6806116724b9e101..a871aa201f124d70530f5cf09d743fe37692a6d2 100644 (file)
@@ -1,21 +1,29 @@
 // Header for PCH test cxx_exprs.cpp
 
 // CXXStaticCastExpr
-typedef typeof(static_cast<void *>(0)) static_cast_result;
+typedef __typeof__(static_cast<void *>(0)) static_cast_result;
 
 // CXXDynamicCastExpr
 struct Base { virtual void f(); };
 struct Derived : Base { };
 Base *base_ptr;
-typedef typeof(dynamic_cast<Derived *>(base_ptr)) dynamic_cast_result;
+typedef __typeof__(dynamic_cast<Derived *>(base_ptr)) dynamic_cast_result;
 
 // CXXReinterpretCastExpr
-typedef typeof(reinterpret_cast<void *>(0)) reinterpret_cast_result;
+typedef __typeof__(reinterpret_cast<void *>(0)) reinterpret_cast_result;
 
 // CXXConstCastExpr
 const char *const_char_ptr_value;
-typedef typeof(const_cast<char *>(const_char_ptr_value)) const_cast_result;
+typedef __typeof__(const_cast<char *>(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;