[cfe-commits] r69119 - in /cfe/trunk: include/clang/AST/Expr.h include/clang/Frontend/PCHBitCodes.h lib/Frontend/PCHReader.cpp lib/Frontend/PCHWriter.cpp test/PCH/exprs.c test/PCH/exprs.h

Douglas Gregor dgregor at apple.com
Tue Apr 14 17:26:06 PDT 2009


Author: dgregor
Date: Tue Apr 14 19:25:59 2009
New Revision: 69119

URL: http://llvm.org/viewvc/llvm-project?rev=69119&view=rev
Log:
PCH support for CStyleCastExpr and BinaryOperator expression kinds.

Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/include/clang/Frontend/PCHBitCodes.h
    cfe/trunk/lib/Frontend/PCHReader.cpp
    cfe/trunk/lib/Frontend/PCHWriter.cpp
    cfe/trunk/test/PCH/exprs.c
    cfe/trunk/test/PCH/exprs.h

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=69119&r1=69118&r2=69119&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Apr 14 19:25:59 2009
@@ -1228,10 +1228,15 @@
   ExplicitCastExpr(StmtClass SC, QualType exprTy, Expr *op, QualType writtenTy) 
     : CastExpr(SC, exprTy, op), TypeAsWritten(writtenTy) {}
 
+  /// \brief Construct an empty explicit cast.
+  ExplicitCastExpr(StmtClass SC, EmptyShell Shell) 
+    : CastExpr(SC, Shell) { }
+
 public:
   /// getTypeAsWritten - Returns the type that this expression is
   /// casting to, as written in the source code.
   QualType getTypeAsWritten() const { return TypeAsWritten; }
+  void setTypeAsWritten(QualType T) { TypeAsWritten = T; }
 
   static bool classof(const Stmt *T) { 
     StmtClass SC = T->getStmtClass();
@@ -1257,9 +1262,16 @@
     ExplicitCastExpr(CStyleCastExprClass, exprTy, op, writtenTy), 
     LPLoc(l), RPLoc(r) {}
 
+  /// \brief Construct an empty C-style explicit cast.
+  explicit CStyleCastExpr(EmptyShell Shell) 
+    : ExplicitCastExpr(CStyleCastExprClass, Shell) { }
+
   SourceLocation getLParenLoc() const { return LPLoc; }
+  void setLParenLoc(SourceLocation L) { LPLoc = L; }
+
   SourceLocation getRParenLoc() const { return RPLoc; }
-  
+  void setRParenLoc(SourceLocation L) { RPLoc = L; }
+
   virtual SourceRange getSourceRange() const {
     return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd());
   }
@@ -1333,10 +1345,21 @@
            "Use ArithAssignBinaryOperator for compound assignments");
   }
 
+  /// \brief Construct an empty binary operator.
+  explicit BinaryOperator(EmptyShell Empty) 
+    : Expr(BinaryOperatorClass, Empty), Opc(Comma) { }
+
   SourceLocation getOperatorLoc() const { return OpLoc; }
+  void setOperatorLoc(SourceLocation L) { OpLoc = L; }
+
   Opcode getOpcode() const { return Opc; }
+  void setOpcode(Opcode O) { Opc = O; }
+
   Expr *getLHS() const { return cast<Expr>(SubExprs[LHS]); }
+  void setLHS(Expr *E) { SubExprs[LHS] = E; }
   Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
+  void setRHS(Expr *E) { SubExprs[RHS] = E; }
+
   virtual SourceRange getSourceRange() const {
     return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd());
   }

Modified: cfe/trunk/include/clang/Frontend/PCHBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHBitCodes.h?rev=69119&r1=69118&r2=69119&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Tue Apr 14 19:25:59 2009
@@ -385,8 +385,12 @@
       EXPR_CHARACTER_LITERAL,
       /// \brief A ParenExpr record.
       EXPR_PAREN,
+      /// \brief A BinaryOperator record.
+      EXPR_BINARY_OPERATOR,
       /// \brief An ImplicitCastExpr record.
-      EXPR_IMPLICIT_CAST
+      EXPR_IMPLICIT_CAST,
+      /// \brief A CStyleCastExpr record.
+      EXPR_CSTYLE_CAST
     };
     /// @}
   }

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=69119&r1=69118&r2=69119&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Tue Apr 14 19:25:59 2009
@@ -239,7 +239,10 @@
     unsigned VisitCharacterLiteral(CharacterLiteral *E);
     unsigned VisitParenExpr(ParenExpr *E);
     unsigned VisitCastExpr(CastExpr *E);
+    unsigned VisitBinaryOperator(BinaryOperator *E);
     unsigned VisitImplicitCastExpr(ImplicitCastExpr *E);
+    unsigned VisitExplicitCastExpr(ExplicitCastExpr *E);
+    unsigned VisitCStyleCastExpr(CStyleCastExpr *E);
   };
 }
 
@@ -301,12 +304,34 @@
   return 1;
 }
 
+unsigned PCHStmtReader::VisitBinaryOperator(BinaryOperator *E) {
+  VisitExpr(E);
+  E->setLHS(ExprStack.end()[-2]);
+  E->setRHS(ExprStack.end()[-1]);
+  E->setOpcode((BinaryOperator::Opcode)Record[Idx++]);
+  E->setOperatorLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  return 2;
+}
+
 unsigned PCHStmtReader::VisitImplicitCastExpr(ImplicitCastExpr *E) {
   VisitCastExpr(E);
   E->setLvalueCast(Record[Idx++]);
   return 1;
 }
 
+unsigned PCHStmtReader::VisitExplicitCastExpr(ExplicitCastExpr *E) {
+  VisitCastExpr(E);
+  E->setTypeAsWritten(Reader.GetType(Record[Idx++]));
+  return 1;
+}
+
+unsigned PCHStmtReader::VisitCStyleCastExpr(CStyleCastExpr *E) {
+  VisitExplicitCastExpr(E);
+  E->setLParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  E->setRParenLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  return 1;
+}
+
 // FIXME: use the diagnostics machinery
 static bool Error(const char *Str) {
   std::fprintf(stderr, "%s\n", Str);
@@ -1618,9 +1643,17 @@
       E = new (Context) ParenExpr(Empty);
       break;
 
+    case pch::EXPR_BINARY_OPERATOR:
+      E = new (Context) BinaryOperator(Empty);
+      break;
+
     case pch::EXPR_IMPLICIT_CAST:
       E = new (Context) ImplicitCastExpr(Empty);
       break;
+
+    case pch::EXPR_CSTYLE_CAST:
+      E = new (Context) CStyleCastExpr(Empty);
+      break;
     }
 
     // We hit an EXPR_STOP, so we're done with this expression.

Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=69119&r1=69118&r2=69119&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Tue Apr 14 19:25:59 2009
@@ -451,7 +451,10 @@
     void VisitCharacterLiteral(CharacterLiteral *E);
     void VisitParenExpr(ParenExpr *E);
     void VisitCastExpr(CastExpr *E);
+    void VisitBinaryOperator(BinaryOperator *E);
     void VisitImplicitCastExpr(ImplicitCastExpr *E);
+    void VisitExplicitCastExpr(ExplicitCastExpr *E);
+    void VisitCStyleCastExpr(CStyleCastExpr *E);
   };
 }
 
@@ -511,12 +514,33 @@
   Writer.WriteSubExpr(E->getSubExpr());
 }
 
+void PCHStmtWriter::VisitBinaryOperator(BinaryOperator *E) {
+  VisitExpr(E);
+  Writer.WriteSubExpr(E->getLHS());
+  Writer.WriteSubExpr(E->getRHS());
+  Record.push_back(E->getOpcode()); // FIXME: stable encoding
+  Writer.AddSourceLocation(E->getOperatorLoc(), Record);
+  Code = pch::EXPR_BINARY_OPERATOR;
+}
+
 void PCHStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
   VisitCastExpr(E);
   Record.push_back(E->isLvalueCast());
   Code = pch::EXPR_IMPLICIT_CAST;
 }
 
+void PCHStmtWriter::VisitExplicitCastExpr(ExplicitCastExpr *E) {
+  VisitCastExpr(E);
+  Writer.AddTypeRef(E->getTypeAsWritten(), Record);
+}
+
+void PCHStmtWriter::VisitCStyleCastExpr(CStyleCastExpr *E) {
+  VisitExplicitCastExpr(E);
+  Writer.AddSourceLocation(E->getLParenLoc(), Record);
+  Writer.AddSourceLocation(E->getRParenLoc(), Record);
+  Code = pch::EXPR_CSTYLE_CAST;
+}
+
 //===----------------------------------------------------------------------===//
 // PCHWriter Implementation
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/test/PCH/exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/exprs.c?rev=69119&r1=69118&r2=69119&view=diff

==============================================================================
--- cfe/trunk/test/PCH/exprs.c (original)
+++ cfe/trunk/test/PCH/exprs.c Tue Apr 14 19:25:59 2009
@@ -17,8 +17,14 @@
 integer_literal *int_ptr2 = &integer;
 long_literal *long_ptr1 = &long_integer;
 
-// FloatingLiteral
+// FloatingLiteral + ParenExpr
 floating_literal *double_ptr = &floating;
 
 // CharacterLiteral
 char_literal *int_ptr3 = &integer;
+
+// BinaryOperator
+add_result *int_ptr4 = &integer;
+
+// CStyleCastExpr
+void_ptr vp1 = &integer;

Modified: cfe/trunk/test/PCH/exprs.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/exprs.h?rev=69119&r1=69118&r2=69119&view=diff

==============================================================================
--- cfe/trunk/test/PCH/exprs.h (original)
+++ cfe/trunk/test/PCH/exprs.h Tue Apr 14 19:25:59 2009
@@ -10,9 +10,15 @@
 typedef typeof(17) integer_literal;
 typedef typeof(17l) long_literal;
 
-// FloatingLiteral
+// FloatingLiteral and ParenExpr
 typedef typeof((42.5)) floating_literal;
 
 // CharacterLiteral
 typedef typeof('a') char_literal;
 
+// BinaryOperator
+typedef typeof(i + Enumerator) add_result;
+
+// CStyleCastExpr
+typedef typeof((void *)0) void_ptr;
+





More information about the cfe-commits mailing list