]> granicus.if.org Git - clang/commitdiff
Added getTrueExpr() and getFalseExpr() to ConditionalOperator. These methods
authorTed Kremenek <kremenek@apple.com>
Mon, 3 Dec 2007 17:09:21 +0000 (17:09 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 3 Dec 2007 17:09:21 +0000 (17:09 +0000)
provide handy accessors to the subexpressions of ConditionalOperator that
automatically take into account the GCC extension where the "LHS" expression is
omitted: e.g x ?: y;. When the LHS expression is available, getTrueExpr() is the
same as getLHS(); when LHS is NULL, getTrueExpr() returns the condition expression.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44536 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Expr.h

index 91cee5ef00c5417255b331f1bbcc2cff4f18be67..c83a76e90903c39d3dd6aa8d8c33956af954032f 100644 (file)
@@ -915,7 +915,24 @@ public:
     SubExprs[RHS] = rhs;
   }
 
+  // getCond - Return the expression representing the condition for
+  //  the ?: operator.
   Expr *getCond() const { return SubExprs[COND]; }
+
+  // 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.  
+  Expr *getTrueExpr() const {
+    return SubExprs[LHS] ? SubExprs[COND] : SubExprs[LHS];
+  }
+  
+  // getTrueExpr - 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 SubExprs[RHS]; }
+  
   Expr *getLHS() const { return SubExprs[LHS]; }
   Expr *getRHS() const { return SubExprs[RHS]; }