aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
authorAbramo Bagnara <abramo.bagnara@gmail.com>2010-05-14 17:07:14 +0000
committerAbramo Bagnara <abramo.bagnara@gmail.com>2010-05-14 17:07:14 +0000
commite17a6436b429e4b18a5e157061fb13bbc677b3b0 (patch)
tree5709f53e62396fe2cbe8e1c63660f6aad26c414d /lib/AST/ExprConstant.cpp
parent0fd3d1f5664149f0a6b62fc847eeabf4d8659360 (diff)
Added Expr::EvaluateAsAnyLValue.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103780 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ExprConstant.cpp')
-rw-r--r--lib/AST/ExprConstant.cpp26
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index b2a192927f..f903035d22 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -106,8 +106,7 @@ static bool EvaluateComplex(const Expr *E, ComplexValue &Res, EvalInfo &Info);
// Misc utilities
//===----------------------------------------------------------------------===//
-static bool IsGlobalLValue(LValue &Value) {
- const Expr *E = Value.Base;
+static bool IsGlobalLValue(const Expr* E) {
if (!E) return true;
if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
@@ -135,7 +134,7 @@ static bool EvalPointerValueAsBool(LValue& Value, bool& Result) {
}
// Require the base expression to be a global l-value.
- if (!IsGlobalLValue(Value)) return false;
+ if (!IsGlobalLValue(Base)) return false;
// We have a non-null base expression. These are generally known to
// be true, but if it'a decl-ref to a weak symbol it can be null at
@@ -2187,7 +2186,7 @@ bool Expr::Evaluate(EvalResult &Result, ASTContext &Ctx) const {
LValue LV;
if (!EvaluatePointer(E, LV, Info))
return false;
- if (!IsGlobalLValue(LV))
+ if (!IsGlobalLValue(LV.Base))
return false;
LV.moveInto(Info.EvalResult.Val);
} else if (E->getType()->isRealFloatingType()) {
@@ -2220,7 +2219,18 @@ bool Expr::EvaluateAsLValue(EvalResult &Result, ASTContext &Ctx) const {
LValue LV;
if (EvaluateLValue(this, LV, Info) &&
!Result.HasSideEffects &&
- IsGlobalLValue(LV)) {
+ IsGlobalLValue(LV.Base)) {
+ LV.moveInto(Result.Val);
+ return true;
+ }
+ return false;
+}
+
+bool Expr::EvaluateAsAnyLValue(EvalResult &Result, ASTContext &Ctx) const {
+ EvalInfo Info(Ctx, Result);
+
+ LValue LV;
+ if (EvaluateLValue(this, LV, Info)) {
LV.moveInto(Result.Val);
return true;
}
@@ -2250,6 +2260,12 @@ APSInt Expr::EvaluateAsInt(ASTContext &Ctx) const {
return EvalResult.Val.getInt();
}
+ bool Expr::EvalResult::isGlobalLValue() const {
+ assert(Val.isLValue());
+ return IsGlobalLValue(Val.getLValueBase());
+ }
+
+
/// isIntegerConstantExpr - this recursive routine will test if an expression is
/// an integer constant expression.