]> granicus.if.org Git - clang/commitdiff
PCH support for CompoundAssignOperator and ConditionalOperator
authorDouglas Gregor <dgregor@apple.com>
Wed, 15 Apr 2009 22:40:36 +0000 (22:40 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 15 Apr 2009 22:40:36 +0000 (22:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69237 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 2311b9cb440db3399c8a94be58980ec4bbf6da97..5634bf4d62bcb6694deda855974398abb5e69e15 100644 (file)
@@ -1469,6 +1469,9 @@ protected:
     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 @@ public:
            "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 @@ public:
     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 @@ public:
   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());
index b9ad1b5b893c0d73640896d183005c1caea2ea03..a944f09bcb1c292c4751fc01884bc43d6dcb6b23 100644 (file)
@@ -411,6 +411,10 @@ namespace clang {
       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.
index 042e56626e0522f0253e89835cac575301a098d7..f9290bac73fbbb74d73def0e9213e06ff4c76386 100644 (file)
@@ -252,6 +252,8 @@ namespace {
     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 @@ unsigned PCHStmtReader::VisitBinaryOperator(BinaryOperator *E) {
   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 @@ Expr *PCHReader::ReadExpr() {
       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;
index a5eba4e67ca9a92198378009badb31338f386a40..0321e4c40baeb56fa17f8e5d0606eab35ad02d96 100644 (file)
@@ -459,6 +459,8 @@ namespace {
     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 @@ void PCHStmtWriter::VisitBinaryOperator(BinaryOperator *E) {
   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());
index dd4333c93d27d1348de5bca326d20fd8ba8c3fd5..49f74dd91a9148e0884c37fb391d58540ef9c098 100644 (file)
@@ -52,5 +52,11 @@ member_ref_double *double_ptr3 = &floating;
 // BinaryOperator
 add_result *int_ptr5 = &integer;
 
+// CompoundAssignOperator
+addeq_result *int_ptr6 = &integer;
+
+// ConditionalOperator
+conditional_operator *double_ptr4 = &floating;
+
 // CStyleCastExpr
 void_ptr vp1 = &integer;
index 0c09e8fcbb7623cbb0afd2bc4358073945cf9a6f..016c4c6beeed2f8864cc34192d12ef78063dda53 100644 (file)
@@ -47,6 +47,12 @@ typedef typeof(((struct S*)0)->x) member_ref_double;
 // 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;