From: Anders Carlsson Date: Sun, 30 Nov 2008 16:19:46 +0000 (+0000) Subject: Add Expr::EvalResult struct. (Not used just yet) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=94deaf675ae60e11c2d9475c6dbfd0c7123160f5;p=clang Add Expr::EvalResult struct. (Not used just yet) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60295 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index dfdca82c74..05c0cebff0 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -14,6 +14,7 @@ #ifndef LLVM_CLANG_AST_EXPR_H #define LLVM_CLANG_AST_EXPR_H +#include "clang/AST/APValue.h" #include "clang/AST/Stmt.h" #include "clang/AST/Type.h" #include "llvm/ADT/APSInt.h" @@ -137,6 +138,30 @@ public: /// isConstantExpr - Return true if this expression is a valid constant expr. bool isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const; + /// EvalResult is a struct with detailed info about an evaluated expression. + struct EvalResult { + /// Val - This is the scalar value the expression can be folded to. + APValue Val; + + /// HasSideEffects - Whether the evaluated expression has side effects. + /// For example, (f() && 0) can be folded, but it still has side effects. + bool HasSideEffects; + + /// Diag - If the expression is unfoldable, then Diag contains a note + /// diagnostic indicating why it's not foldable. DiagLoc indicates a caret + /// position for the error, and DiagExpr is the expression that caused + /// the error. + /// If the expression is foldable, but not an integer constant expression, + /// Diag contains a note diagnostic that describes why it isn't an integer + /// constant expression. If the expression *is* an integer constant + /// expression, then Diag will be zero. + unsigned Diag; + const Expr *DiagExpr; + SourceLocation DiagLoc; + + EvalResult() : HasSideEffects(false), Diag(0), DiagExpr(0) {} + }; + /// Evaluate - Return true if this is a constant which we can fold using /// any crazy technique (that has nothing to do with language standards) that /// we want to. If this function returns true, it returns the folded constant