[cfe-commits] r69237 - 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
Wed Apr 15 15:40:37 PDT 2009


Author: dgregor
Date: Wed Apr 15 17:40:36 2009
New Revision: 69237

URL: http://llvm.org/viewvc/llvm-project?rev=69237&view=rev
Log:
PCH support for CompoundAssignOperator and ConditionalOperator

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=69237&r1=69236&r2=69237&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Apr 15 17:40:36 2009
@@ -1469,6 +1469,9 @@
     SubExprs[LHS] = lhs;
     SubExprs[RHS] = rhs;
   }
+
+  BinaryOperator(StmtClass SC, EmptyShell Empty) 
+    : Expr(SC, Empty), Opc(MulAssign) { }
 };
 
 /// CompoundAssignOperator - For compound assignments (e.g. +=), we keep
@@ -1492,12 +1495,19 @@
            "Only should be used for compound assignments");
   }
 
+  /// \brief Build an empty compound assignment operator expression.
+  explicit CompoundAssignOperator(EmptyShell Empty)
+    : BinaryOperator(CompoundAssignOperatorClass, Empty) { }
+
   // The two computation types are the type the LHS is converted
   // to for the computation and the type of the result; the two are
   // distinct in a few cases (specifically, int+=ptr and ptr-=ptr).
   QualType getComputationLHSType() const { return ComputationLHSType; }
+  void setComputationLHSType(QualType T) { ComputationLHSType = T; }
+
   QualType getComputationResultType() const { return ComputationResultType; }
-  
+  void setComputationResultType(QualType T) { ComputationResultType = T; }
+
   static bool classof(const CompoundAssignOperator *) { return true; }
   static bool classof(const Stmt *S) { 
     return S->getStmtClass() == CompoundAssignOperatorClass; 
@@ -1529,9 +1539,14 @@
     SubExprs[RHS] = rhs;
   }
 
+  /// \brief Build an empty conditional operator.
+  explicit ConditionalOperator(EmptyShell Empty)
+    : Expr(ConditionalOperatorClass, Empty) { }
+
   // getCond - Return the expression representing the condition for
   //  the ?: operator.
   Expr *getCond() const { return cast<Expr>(SubExprs[COND]); }
+  void setCond(Expr *E) { SubExprs[COND] = E; }
 
   // getTrueExpr - Return the subexpression representing the value of the ?:
   //  expression if the condition evaluates to true.  In most cases this value
@@ -1548,7 +1563,10 @@
   Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
   
   Expr *getLHS() const { return cast_or_null<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(getCond()->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=69237&r1=69236&r2=69237&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Wed Apr 15 17:40:36 2009
@@ -411,6 +411,10 @@
       EXPR_MEMBER,
       /// \brief A BinaryOperator record.
       EXPR_BINARY_OPERATOR,
+      /// \brief A CompoundAssignOperator record.
+      EXPR_COMPOUND_ASSIGN_OPERATOR,
+      /// \brief A ConditionOperator record.
+      EXPR_CONDITIONAL_OPERATOR,
       /// \brief An ImplicitCastExpr record.
       EXPR_IMPLICIT_CAST,
       /// \brief A CStyleCastExpr record.

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

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Wed Apr 15 17:40:36 2009
@@ -252,6 +252,8 @@
     unsigned VisitMemberExpr(MemberExpr *E);
     unsigned VisitCastExpr(CastExpr *E);
     unsigned VisitBinaryOperator(BinaryOperator *E);
+    unsigned VisitCompoundAssignOperator(CompoundAssignOperator *E);
+    unsigned VisitConditionalOperator(ConditionalOperator *E);
     unsigned VisitImplicitCastExpr(ImplicitCastExpr *E);
     unsigned VisitExplicitCastExpr(ExplicitCastExpr *E);
     unsigned VisitCStyleCastExpr(CStyleCastExpr *E);
@@ -401,6 +403,21 @@
   return 2;
 }
 
+unsigned PCHStmtReader::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
+  VisitBinaryOperator(E);
+  E->setComputationLHSType(Reader.GetType(Record[Idx++]));
+  E->setComputationResultType(Reader.GetType(Record[Idx++]));
+  return 2;
+}
+
+unsigned PCHStmtReader::VisitConditionalOperator(ConditionalOperator *E) {
+  VisitExpr(E);
+  E->setCond(ExprStack[ExprStack.size() - 3]);
+  E->setLHS(ExprStack[ExprStack.size() - 2]);
+  E->setRHS(ExprStack[ExprStack.size() - 1]);
+  return 3;
+}
+
 unsigned PCHStmtReader::VisitImplicitCastExpr(ImplicitCastExpr *E) {
   VisitCastExpr(E);
   E->setLvalueCast(Record[Idx++]);
@@ -1917,6 +1934,14 @@
       E = new (Context) BinaryOperator(Empty);
       break;
 
+    case pch::EXPR_COMPOUND_ASSIGN_OPERATOR:
+      E = new (Context) CompoundAssignOperator(Empty);
+      break;
+
+    case pch::EXPR_CONDITIONAL_OPERATOR:
+      E = new (Context) ConditionalOperator(Empty);
+      break;
+
     case pch::EXPR_IMPLICIT_CAST:
       E = new (Context) ImplicitCastExpr(Empty);
       break;

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

==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Wed Apr 15 17:40:36 2009
@@ -459,6 +459,8 @@
     void VisitMemberExpr(MemberExpr *E);
     void VisitCastExpr(CastExpr *E);
     void VisitBinaryOperator(BinaryOperator *E);
+    void VisitCompoundAssignOperator(CompoundAssignOperator *E);
+    void VisitConditionalOperator(ConditionalOperator *E);
     void VisitImplicitCastExpr(ImplicitCastExpr *E);
     void VisitExplicitCastExpr(ExplicitCastExpr *E);
     void VisitCStyleCastExpr(CStyleCastExpr *E);
@@ -602,6 +604,21 @@
   Code = pch::EXPR_BINARY_OPERATOR;
 }
 
+void PCHStmtWriter::VisitCompoundAssignOperator(CompoundAssignOperator *E) {
+  VisitBinaryOperator(E);
+  Writer.AddTypeRef(E->getComputationLHSType(), Record);
+  Writer.AddTypeRef(E->getComputationResultType(), Record);
+  Code = pch::EXPR_COMPOUND_ASSIGN_OPERATOR;
+}
+
+void PCHStmtWriter::VisitConditionalOperator(ConditionalOperator *E) {
+  VisitExpr(E);
+  Writer.WriteSubExpr(E->getCond());
+  Writer.WriteSubExpr(E->getLHS());
+  Writer.WriteSubExpr(E->getRHS());
+  Code = pch::EXPR_CONDITIONAL_OPERATOR;
+}
+
 void PCHStmtWriter::VisitImplicitCastExpr(ImplicitCastExpr *E) {
   VisitCastExpr(E);
   Record.push_back(E->isLvalueCast());

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

==============================================================================
--- cfe/trunk/test/PCH/exprs.c (original)
+++ cfe/trunk/test/PCH/exprs.c Wed Apr 15 17:40:36 2009
@@ -52,5 +52,11 @@
 // BinaryOperator
 add_result *int_ptr5 = &integer;
 
+// CompoundAssignOperator
+addeq_result *int_ptr6 = &integer;
+
+// ConditionalOperator
+conditional_operator *double_ptr4 = &floating;
+
 // 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=69237&r1=69236&r2=69237&view=diff

==============================================================================
--- cfe/trunk/test/PCH/exprs.h (original)
+++ cfe/trunk/test/PCH/exprs.h Wed Apr 15 17:40:36 2009
@@ -47,6 +47,12 @@
 // BinaryOperator
 typedef typeof(i + Enumerator) add_result;
 
+// CompoundAssignOperator
+typedef typeof(i += Enumerator) addeq_result;
+
+// ConditionalOperator
+typedef typeof(i? : d0) conditional_operator;
+
 // CStyleCastExpr
 typedef typeof((void *)0) void_ptr;
 





More information about the cfe-commits mailing list