[cfe-commits] r112612 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/StmtDumper.cpp lib/Rewrite/RewriteObjC.cpp lib/Sema/SemaExpr.cpp lib/Serialization/ASTReaderStmt.cpp lib/Serialization/ASTWriterStmt.cpp

Fariborz Jahanian fjahanian at apple.com
Tue Aug 31 11:02:20 PDT 2010


Author: fjahanian
Date: Tue Aug 31 13:02:20 2010
New Revision: 112612

URL: http://llvm.org/viewvc/llvm-project?rev=112612&view=rev
Log:
AST work to support [C++] [IRgen] for ?: with missing LHS
This is also pr7726 and wip. No change in functionality
at this time.

Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/lib/AST/StmtDumper.cpp
    cfe/trunk/lib/Rewrite/RewriteObjC.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
    cfe/trunk/lib/Serialization/ASTWriterStmt.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=112612&r1=112611&r2=112612&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Aug 31 13:02:20 2010
@@ -2391,10 +2391,11 @@
 class ConditionalOperator : public Expr {
   enum { COND, LHS, RHS, END_EXPR };
   Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
+  Stmt* Save;
   SourceLocation QuestionLoc, ColonLoc;
 public:
   ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs,
-                      SourceLocation CLoc, Expr *rhs, QualType t)
+                      SourceLocation CLoc, Expr *rhs, Expr *save, QualType t)
     : Expr(ConditionalOperatorClass, t,
            // FIXME: the type of the conditional operator doesn't
            // depend on the type of the conditional, but the standard
@@ -2408,6 +2409,7 @@
     SubExprs[COND] = cond;
     SubExprs[LHS] = lhs;
     SubExprs[RHS] = rhs;
+    Save = save;
   }
 
   /// \brief Build an empty conditional operator.
@@ -2420,25 +2422,31 @@
   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
-  //  will be the same as getLHS() except a GCC extension allows the left
-  //  subexpression to be omitted, and instead of the condition be returned.
-  //  e.g: x ?: y is shorthand for x ? x : y, except that the expression "x"
-  //  is only evaluated once.
+  //  expression if the condition evaluates to true.  
   Expr *getTrueExpr() const {
-    return cast<Expr>(SubExprs[LHS] ? SubExprs[LHS] : SubExprs[COND]);
+    return cast<Expr>(!Save ? SubExprs[LHS] : SubExprs[COND]);
   }
 
   // getFalseExpr - Return the subexpression representing the value of the ?:
   // expression if the condition evaluates to false. This is the same as getRHS.
   Expr *getFalseExpr() const { return cast<Expr>(SubExprs[RHS]); }
+  
+  // getSaveExpr - In most cases this value will be null. Except a GCC extension 
+  // allows the left subexpression to be omitted, and instead of that condition 
+  // be returned. e.g: x ?: y is shorthand for x ? x : y, except that the 
+  // expression "x" is only evaluated once. Under this senario, this function
+  // returns the original, non-converted condition expression for the ?:operator
+  Expr *getSaveExpr() const { return Save? cast<Expr>(Save) : (Expr*)0; }
 
-  Expr *getLHS() const { return cast_or_null<Expr>(SubExprs[LHS]); }
+  Expr *getLHS() const { return Save ? 0 : 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; }
 
+  Expr *getSAVE() const { return Save? cast<Expr>(Save) : (Expr*)0; }
+  void setSAVE(Expr *E) { Save = E; }
+  
   SourceLocation getQuestionLoc() const { return QuestionLoc; }
   void setQuestionLoc(SourceLocation L) { QuestionLoc = L; }
 

Modified: cfe/trunk/lib/AST/StmtDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtDumper.cpp?rev=112612&r1=112611&r2=112612&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtDumper.cpp (original)
+++ cfe/trunk/lib/AST/StmtDumper.cpp Tue Aug 31 13:02:20 2010
@@ -65,6 +65,13 @@
               OS << '\n';
               DumpSubTree(*CI++);
             }
+            if (const ConditionalOperator *CO = 
+                  dyn_cast<ConditionalOperator>(S)) {
+              if (CO->getSAVE()) {
+                OS << '\n';
+                DumpSubTree(CO->getSAVE());
+              }
+            }
           }
         }
         OS << ')';

Modified: cfe/trunk/lib/Rewrite/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/RewriteObjC.cpp?rev=112612&r1=112611&r2=112612&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/RewriteObjC.cpp Tue Aug 31 13:02:20 2010
@@ -3041,8 +3041,10 @@
     ConditionalOperator *CondExpr =
       new (Context) ConditionalOperator(lessThanExpr,
                                         SourceLocation(), CE,
-                                        SourceLocation(), STCE, returnType);
-    ReplacingStmt = new (Context) ParenExpr(SourceLocation(), SourceLocation(), CondExpr);
+                                        SourceLocation(), STCE, (Expr*)0,
+                                        returnType);
+    ReplacingStmt = new (Context) ParenExpr(SourceLocation(), SourceLocation(), 
+                                            CondExpr);
   }
   // delete Exp; leak for now, see RewritePropertySetter() usage for more info.
   return ReplacingStmt;
@@ -4566,7 +4568,8 @@
     ConditionalOperator *CondExpr =
       new (Context) ConditionalOperator(CONDExp,
                                       SourceLocation(), cast<Expr>(LHSStmt),
-                                      SourceLocation(), cast<Expr>(RHSStmt), 
+                                      SourceLocation(), cast<Expr>(RHSStmt),
+                                      (Expr*)0,
                                       Exp->getType());
     return CondExpr;
   } else if (const ObjCIvarRefExpr *IRE = dyn_cast<ObjCIvarRefExpr>(BlockExp)) {

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=112612&r1=112611&r2=112612&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Aug 31 13:02:20 2010
@@ -4521,8 +4521,10 @@
   // If this is the gnu "x ?: y" extension, analyze the types as though the LHS
   // was the condition.
   bool isLHSNull = LHSExpr == 0;
-  if (isLHSNull)
-    LHSExpr = CondExpr;
+  Expr *SAVEExpr = 0;
+  if (isLHSNull) {
+    LHSExpr = SAVEExpr = CondExpr;
+  }
 
   QualType result = CheckConditionalOperands(CondExpr, LHSExpr,
                                              RHSExpr, QuestionLoc);
@@ -4530,8 +4532,9 @@
     return ExprError();
 
   return Owned(new (Context) ConditionalOperator(CondExpr, QuestionLoc,
-                                                 isLHSNull ? 0 : LHSExpr,
-                                                 ColonLoc, RHSExpr, result));
+                                                 LHSExpr, ColonLoc, 
+                                                 RHSExpr, SAVEExpr,
+                                                 result));
 }
 
 // CheckPointerTypesForAssignment - This is a very tricky routine (despite

Modified: cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderStmt.cpp?rev=112612&r1=112611&r2=112612&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderStmt.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderStmt.cpp Tue Aug 31 13:02:20 2010
@@ -592,6 +592,7 @@
   E->setCond(Reader.ReadSubExpr());
   E->setLHS(Reader.ReadSubExpr());
   E->setRHS(Reader.ReadSubExpr());
+  E->setSAVE(Reader.ReadSubExpr());
   E->setQuestionLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
   E->setColonLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
 }

Modified: cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterStmt.cpp?rev=112612&r1=112611&r2=112612&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterStmt.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterStmt.cpp Tue Aug 31 13:02:20 2010
@@ -598,6 +598,7 @@
   Writer.AddStmt(E->getCond());
   Writer.AddStmt(E->getLHS());
   Writer.AddStmt(E->getRHS());
+  Writer.AddStmt(E->getSAVE());
   Writer.AddSourceLocation(E->getQuestionLoc(), Record);
   Writer.AddSourceLocation(E->getColonLoc(), Record);
   Code = serialization::EXPR_CONDITIONAL_OPERATOR;





More information about the cfe-commits mailing list