]> granicus.if.org Git - clang/commitdiff
Add PCH support for CXXStaticCastExpr, CXXDynamicCastExpr, CXXReinterpretCastExpr...
authorSam Weinig <sam.weinig@gmail.com>
Sat, 16 Jan 2010 21:21:01 +0000 (21:21 +0000)
committerSam Weinig <sam.weinig@gmail.com>
Sat, 16 Jan 2010 21:21:01 +0000 (21:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93658 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/ExprCXX.h
include/clang/Frontend/PCHBitCodes.h
lib/Frontend/PCHReaderStmt.cpp
lib/Frontend/PCHWriterStmt.cpp
test/PCH/cxx_exprs.cpp [new file with mode: 0644]
test/PCH/cxx_exprs.h [new file with mode: 0644]

index 699c1f5414d02a99519c5ea965c819ad4d112b75..ab22ba30b139981dc3078967ea83a83fc5acd447 100644 (file)
@@ -121,6 +121,9 @@ protected:
                    TypeSourceInfo *writtenTy, SourceLocation l)
     : ExplicitCastExpr(SC, ty, kind, op, writtenTy), Loc(l) {}
 
+  explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell)
+    : ExplicitCastExpr(SC, Shell) { }
+
 public:
   const char *getCastName() const;
 
@@ -157,6 +160,9 @@ public:
                     TypeSourceInfo *writtenTy, SourceLocation l)
     : CXXNamedCastExpr(CXXStaticCastExprClass, ty, kind, op, writtenTy, l) {}
 
+  explicit CXXStaticCastExpr(EmptyShell Empty)
+    : CXXNamedCastExpr(CXXStaticCastExprClass, Empty) { }
+
   static bool classof(const Stmt *T) {
     return T->getStmtClass() == CXXStaticCastExprClass;
   }
@@ -175,6 +181,9 @@ public:
                      TypeSourceInfo *writtenTy, SourceLocation l)
     : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, kind, op, writtenTy, l) {}
 
+  explicit CXXDynamicCastExpr(EmptyShell Empty)
+    : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty) { }
+
   static bool classof(const Stmt *T) {
     return T->getStmtClass() == CXXDynamicCastExprClass;
   }
@@ -194,6 +203,9 @@ public:
     : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, kind, op,
                        writtenTy, l) {}
 
+  explicit CXXReinterpretCastExpr(EmptyShell Empty)
+    : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty) { }
+
   static bool classof(const Stmt *T) {
     return T->getStmtClass() == CXXReinterpretCastExprClass;
   }
@@ -211,6 +223,9 @@ public:
                    SourceLocation l)
     : CXXNamedCastExpr(CXXConstCastExprClass, ty, CK_NoOp, op, writtenTy, l) {}
 
+  explicit CXXConstCastExpr(EmptyShell Empty)
+    : CXXNamedCastExpr(CXXConstCastExprClass, Empty) { }
+
   static bool classof(const Stmt *T) {
     return T->getStmtClass() == CXXConstCastExprClass;
   }
@@ -632,8 +647,13 @@ public:
                        writtenTy),
       TyBeginLoc(tyBeginLoc), RParenLoc(rParenLoc) {}
 
+  explicit CXXFunctionalCastExpr(EmptyShell Shell)
+    : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell) { }
+
   SourceLocation getTypeBeginLoc() const { return TyBeginLoc; }
+  void setTypeBeginLoc(SourceLocation L) { TyBeginLoc = L; }
   SourceLocation getRParenLoc() const { return RParenLoc; }
+  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
 
   virtual SourceRange getSourceRange() const {
     return SourceRange(TyBeginLoc, RParenLoc);
index 536bd4139006724caade2d5182d29e07edd78a1e..d9d74dcdc47e49375d8a1d5e8b444bc931ba671f 100644 (file)
@@ -676,7 +676,17 @@ namespace clang {
       /// \brief A CXXOperatorCallExpr record.
       EXPR_CXX_OPERATOR_CALL,
       /// \brief A CXXConstructExpr record.
-      EXPR_CXX_CONSTRUCT
+      EXPR_CXX_CONSTRUCT,
+      // \brief A CXXStaticCastExpr record.
+      EXPR_CXX_STATIC_CAST,
+      // \brief A CXXDynamicCastExpr record.
+      EXPR_CXX_DYNAMIC_CAST,
+      // \brief A CXXReinterpretCastExpr record.
+      EXPR_CXX_REINTERPRET_CAST,
+      // \brief A CXXConstCastExpr record.
+      EXPR_CXX_CONST_CAST,
+      // \brief A CXXFunctionalCastExpr record.
+      EXPR_CXX_FUNCTIONAL_CAST
     };
 
     /// \brief The kinds of designators that can occur in a
index ff985c3ed56728a870a889acfe9e3ba148b2e962..c49f5e8fa451cbed8e2e5d05b5700ad76d132bce 100644 (file)
@@ -117,6 +117,12 @@ namespace {
 
     unsigned VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E);
     unsigned VisitCXXConstructExpr(CXXConstructExpr *E);
+    unsigned VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
+    unsigned VisitCXXStaticCastExpr(CXXStaticCastExpr *E);
+    unsigned VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E);
+    unsigned VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E);
+    unsigned VisitCXXConstCastExpr(CXXConstCastExpr *E);
+    unsigned VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E);
   };
 }
 
@@ -868,6 +874,35 @@ unsigned PCHStmtReader::VisitCXXConstructExpr(CXXConstructExpr *E) {
   return E->getNumArgs();
 }
 
+unsigned PCHStmtReader::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
+  unsigned num = VisitExplicitCastExpr(E);
+  E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  return num;
+}
+
+unsigned PCHStmtReader::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
+  return VisitCXXNamedCastExpr(E);
+}
+
+unsigned PCHStmtReader::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
+  return VisitCXXNamedCastExpr(E);
+}
+
+unsigned PCHStmtReader::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
+  return VisitCXXNamedCastExpr(E);
+}
+
+unsigned PCHStmtReader::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
+  return VisitCXXNamedCastExpr(E);
+}
+
+unsigned PCHStmtReader::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
+  unsigned num = VisitExplicitCastExpr(E);
+  E->setTypeBeginLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  return num;
+}
+
 // 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
@@ -1176,6 +1211,28 @@ Stmt *PCHReader::ReadStmt(llvm::BitstreamCursor &Cursor) {
       S = new (Context) CXXConstructExpr(Empty, *Context,
                                       Record[PCHStmtReader::NumExprFields + 2]);
       break;
+
+    case pch::EXPR_CXX_STATIC_CAST:
+      S = new (Context) CXXStaticCastExpr(Empty);
+      break;
+
+    case pch::EXPR_CXX_DYNAMIC_CAST:
+      S = new (Context) CXXDynamicCastExpr(Empty);
+      break;
+
+    case pch::EXPR_CXX_REINTERPRET_CAST:
+      S = new (Context) CXXReinterpretCastExpr(Empty);
+      break;
+
+    case pch::EXPR_CXX_CONST_CAST:
+      S = new (Context) CXXConstCastExpr(Empty);
+      break;
+
+    case pch::EXPR_CXX_FUNCTIONAL_CAST:
+      S = new (Context) CXXFunctionalCastExpr(Empty);
+      break;
+
+
     }
 
     // We hit a STMT_STOP, so we're done with this expression.
index 2174aa5eb300a8ae402c68c7aedb828d2ba400ce..a5ad859b651fa89a623b4d904bf8af975dc9722f 100644 (file)
@@ -112,6 +112,12 @@ namespace {
     // C++ Statements
     void VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E);
     void VisitCXXConstructExpr(CXXConstructExpr *E);
+    void VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
+    void VisitCXXStaticCastExpr(CXXStaticCastExpr *E);
+    void VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E);
+    void VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E);
+    void VisitCXXConstCastExpr(CXXConstCastExpr *E);
+    void VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E);
   };
 }
 
@@ -795,6 +801,38 @@ void PCHStmtWriter::VisitCXXConstructExpr(CXXConstructExpr *E) {
   Code = pch::EXPR_CXX_CONSTRUCT;
 }
 
+void PCHStmtWriter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) {
+  VisitExplicitCastExpr(E);
+  Writer.AddSourceLocation(E->getOperatorLoc(), Record);
+}
+
+void PCHStmtWriter::VisitCXXStaticCastExpr(CXXStaticCastExpr *E) {
+  VisitCXXNamedCastExpr(E);
+  Code = pch::EXPR_CXX_STATIC_CAST;
+}
+
+void PCHStmtWriter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
+  VisitCXXNamedCastExpr(E);
+  Code = pch::EXPR_CXX_DYNAMIC_CAST;
+}
+
+void PCHStmtWriter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *E) {
+  VisitCXXNamedCastExpr(E);
+  Code = pch::EXPR_CXX_REINTERPRET_CAST;
+}
+
+void PCHStmtWriter::VisitCXXConstCastExpr(CXXConstCastExpr *E) {
+  VisitCXXNamedCastExpr(E);
+  Code = pch::EXPR_CXX_CONST_CAST;
+}
+
+void PCHStmtWriter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *E) {
+  VisitExplicitCastExpr(E);
+  Writer.AddSourceLocation(E->getTypeBeginLoc(), Record);
+  Writer.AddSourceLocation(E->getRParenLoc(), Record);
+  Code = pch::EXPR_CXX_FUNCTIONAL_CAST;
+}
+
 //===----------------------------------------------------------------------===//
 // PCHWriter Implementation
 //===----------------------------------------------------------------------===//
diff --git a/test/PCH/cxx_exprs.cpp b/test/PCH/cxx_exprs.cpp
new file mode 100644 (file)
index 0000000..51269d5
--- /dev/null
@@ -0,0 +1,26 @@
+// Test this without pch.
+// RUN: %clang_cc1 -include %S/cxx_exprs.h -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 
+
+int integer;
+double floating;
+char character;
+
+// CXXStaticCastExpr
+static_cast_result void_ptr = &integer;
+
+// CXXDynamicCastExpr
+Derived *d;
+dynamic_cast_result derived_ptr = d;
+
+// CXXReinterpretCastExpr
+reinterpret_cast_result void_ptr2 = &integer;
+
+// CXXConstCastExpr
+const_cast_result char_ptr = &character;
+
+// CXXFunctionalCastExpr
+functional_cast_result *double_ptr = &floating;
diff --git a/test/PCH/cxx_exprs.h b/test/PCH/cxx_exprs.h
new file mode 100644 (file)
index 0000000..b649428
--- /dev/null
@@ -0,0 +1,21 @@
+// Header for PCH test cxx_exprs.cpp
+
+// CXXStaticCastExpr
+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;
+
+// CXXReinterpretCastExpr
+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;
+
+// CXXFunctionalCastExpr
+int int_value;
+typedef typeof(double(int_value)) functional_cast_result;