[cfe-commits] r80097 - in /cfe/trunk: include/clang/AST/Expr.h lib/Frontend/PCHReaderStmt.cpp lib/Frontend/PCHWriterStmt.cpp lib/Frontend/RewriteObjC.cpp lib/Sema/SemaExpr.cpp lib/Sema/TreeTransform.h

Douglas Gregor dgregor at apple.com
Wed Aug 26 07:37:04 PDT 2009


Author: dgregor
Date: Wed Aug 26 09:37:04 2009
New Revision: 80097

URL: http://llvm.org/viewvc/llvm-project?rev=80097&view=rev
Log:
Source location information for ? and : in a ConditionalOperator, from Enea Zaffanella

Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/lib/Frontend/PCHReaderStmt.cpp
    cfe/trunk/lib/Frontend/PCHWriterStmt.cpp
    cfe/trunk/lib/Frontend/RewriteObjC.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/TreeTransform.h

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

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Aug 26 09:37:04 2009
@@ -1546,8 +1546,10 @@
 class ConditionalOperator : public Expr {
   enum { COND, LHS, RHS, END_EXPR };
   Stmt* SubExprs[END_EXPR]; // Left/Middle/Right hand sides.
+  SourceLocation QuestionLoc, ColonLoc;
 public:
-  ConditionalOperator(Expr *cond, Expr *lhs, Expr *rhs, QualType t)
+  ConditionalOperator(Expr *cond, SourceLocation QLoc, Expr *lhs,
+                      SourceLocation CLoc, Expr *rhs, QualType t)
     : Expr(ConditionalOperatorClass, t,
            // FIXME: the type of the conditional operator doesn't
            // depend on the type of the conditional, but the standard
@@ -1555,7 +1557,9 @@
            ((lhs && lhs->isTypeDependent()) || (rhs && rhs->isTypeDependent())),
            (cond->isValueDependent() || 
             (lhs && lhs->isValueDependent()) ||
-            (rhs && rhs->isValueDependent()))) {
+            (rhs && rhs->isValueDependent()))),
+      QuestionLoc(QLoc),
+      ColonLoc(CLoc) {
     SubExprs[COND] = cond;
     SubExprs[LHS] = lhs;
     SubExprs[RHS] = rhs;
@@ -1590,6 +1594,12 @@
   Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); }
   void setRHS(Expr *E) { SubExprs[RHS] = E; }
 
+  SourceLocation getQuestionLoc() const { return QuestionLoc; }
+  void setQuestionLoc(SourceLocation L) { QuestionLoc = L; }
+
+  SourceLocation getColonLoc() const { return ColonLoc; }
+  void setColonLoc(SourceLocation L) { ColonLoc = L; }
+
   virtual SourceRange getSourceRange() const {
     return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd());
   }

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

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderStmt.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderStmt.cpp Wed Aug 26 09:37:04 2009
@@ -491,6 +491,8 @@
   E->setCond(cast<Expr>(StmtStack[StmtStack.size() - 3]));
   E->setLHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 2]));
   E->setRHS(cast_or_null<Expr>(StmtStack[StmtStack.size() - 1]));
+  E->setQuestionLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
+  E->setColonLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
   return 3;
 }
 

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

==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriterStmt.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriterStmt.cpp Wed Aug 26 09:37:04 2009
@@ -453,6 +453,8 @@
   Writer.WriteSubStmt(E->getCond());
   Writer.WriteSubStmt(E->getLHS());
   Writer.WriteSubStmt(E->getRHS());
+  Writer.AddSourceLocation(E->getQuestionLoc(), Record);
+  Writer.AddSourceLocation(E->getColonLoc(), Record);
   Code = pch::EXPR_CONDITIONAL_OPERATOR;
 }
 

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

==============================================================================
--- cfe/trunk/lib/Frontend/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Frontend/RewriteObjC.cpp Wed Aug 26 09:37:04 2009
@@ -2591,7 +2591,9 @@
                                                       SourceLocation());
     // (sizeof(returnType) <= 8 ? objc_msgSend(...) : objc_msgSend_stret(...))
     ConditionalOperator *CondExpr = 
-      new (Context) ConditionalOperator(lessThanExpr, CE, STCE, returnType);
+      new (Context) ConditionalOperator(lessThanExpr,
+                                        SourceLocation(), CE,
+                                        SourceLocation(), STCE, returnType);
     ReplacingStmt = new (Context) ParenExpr(SourceLocation(), SourceLocation(), CondExpr);
   }
   // delete Exp; leak for now, see RewritePropertySetter() usage for more info. 

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=80097&r1=80096&r2=80097&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Aug 26 09:37:04 2009
@@ -3387,9 +3387,9 @@
   Cond.release();
   LHS.release();
   RHS.release();
-  return Owned(new (Context) ConditionalOperator(CondExpr,
+  return Owned(new (Context) ConditionalOperator(CondExpr, QuestionLoc,
                                                  isLHSNull ? 0 : LHSExpr,
-                                                 RHSExpr, result));
+                                                 ColonLoc, RHSExpr, result));
 }
 
 // CheckPointerTypesForAssignment - This is a very tricky routine (despite

Modified: cfe/trunk/lib/Sema/TreeTransform.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=80097&r1=80096&r2=80097&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/TreeTransform.h (original)
+++ cfe/trunk/lib/Sema/TreeTransform.h Wed Aug 26 09:37:04 2009
@@ -3023,13 +3023,10 @@
       RHS.get() == E->getRHS())
     return SemaRef.Owned(E->Retain());
   
-  // FIXM: ? and : locations are broken.
-  SourceLocation FakeQuestionLoc = E->getCond()->getLocEnd();
-  SourceLocation FakeColonLoc = E->getFalseExpr()->getLocStart();
   return getDerived().RebuildConditionalOperator(move(Cond), 
-                                                 FakeQuestionLoc,
+                                                 E->getQuestionLoc(),
                                                  move(LHS), 
-                                                 FakeColonLoc,
+                                                 E->getColonLoc(),
                                                  move(RHS));
 }
   





More information about the cfe-commits mailing list