[cfe-commits] r76947 - /cfe/trunk/lib/Analysis/CFG.cpp

Chris Lattner clattner at apple.com
Thu Jul 23 23:20:16 PDT 2009


On Jul 23, 2009, at 9:47 PM, Ted Kremenek wrote:
> +++ cfe/trunk/lib/Analysis/CFG.cpp Thu Jul 23 23:47:11 2009
> @@ -135,18 +135,29 @@
>   bool FinishBlock(CFGBlock* B);
>   CFGBlock *addStmt(Stmt *S) { return Visit(S, true); }
>
> +  class TryResult {

Please add a doxygen comment.

> +    int X;
> +  public:
> +    TryResult(bool b) : X(b ? 1 : 0) {}
> +    TryResult() : X(-1) {}
> +
> +    bool isTrue() const { return X == 1; }
> +    bool isFalse() const { return X == 0; }
> +    bool isKnown() const { return X >= 0; }
> +    void negate() {
> +      assert(isKnown());
> +      X ^= 0x1;
> +    }
> +  };
> +
>   /// TryEvaluateBool - Try and evaluate the Stmt and return 0 or 1
>   /// if we can evaluate to a known value, otherwise return -1.
> -  int TryEvaluateBool(Expr *S) {
> +  TryResult TryEvaluateBool(Expr *S) {
>     Expr::EvalResult Result;
> +    if (S->Evaluate(Result, *Context) && Result.Val.isInt())
> +      return Result.Val.getInt().getBoolValue() ? true : false;

How about: return Result.Val.getInt().getBoolValue(); instead of  
using ?:.

-Chris



More information about the cfe-commits mailing list