From 395a2abf0028968d85958610e393e067885dc14f Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Mon, 3 Dec 2007 17:09:21 +0000 Subject: [PATCH] Added getTrueExpr() and getFalseExpr() to ConditionalOperator. These methods 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 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 91cee5ef00..c83a76e909 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -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]; } -- 2.40.0