[cfe-commits] r44536 - /cfe/trunk/include/clang/AST/Expr.h
Ted Kremenek
kremenek at apple.com
Mon Dec 3 09:09:22 PST 2007
Author: kremenek
Date: Mon Dec 3 11:09:21 2007
New Revision: 44536
URL: http://llvm.org/viewvc/llvm-project?rev=44536&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/AST/Expr.h
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=44536&r1=44535&r2=44536&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Mon Dec 3 11:09:21 2007
@@ -915,7 +915,24 @@
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]; }
More information about the cfe-commits
mailing list