/// isConstantExpr - Return true if this expression is a valid constant expr.
bool isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const;
- /// tryEvaluate - Return true if this is a constant which we can fold using
+ /// 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
/// in Result.
- bool tryEvaluate(APValue& Result, ASTContext &Ctx) const;
+ bool Evaluate(APValue& Result, ASTContext &Ctx) const;
- /// isEvaluatable - Call tryEvaluate to see if this expression can be constant
+ /// isEvaluatable - Call Evaluate to see if this expression can be constant
/// folded, but discard the result.
bool isEvaluatable(ASTContext &Ctx) const;
// reject it.
if (CE->isBuiltinCall()) {
APValue ResultAP;
- if (CE->tryEvaluate(ResultAP, Ctx)) {
+ if (CE->Evaluate(ResultAP, Ctx)) {
Result = ResultAP.getInt();
break; // It is a constant, expand it.
}
// __builtin_constant_p always has one operand: it returns true if that
// operand can be folded, false otherwise.
APValue Res;
- Result = E->getArg(0)->tryEvaluate(Res, Info.Ctx);
+ Result = E->getArg(0)->Evaluate(Res, Info.Ctx);
return true;
}
}
}
//===----------------------------------------------------------------------===//
-// Top level TryEvaluate.
+// Top level Expr::Evaluate method.
//===----------------------------------------------------------------------===//
-/// tryEvaluate - Return true if this is a constant which we can fold using
+/// 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
/// in Result.
-bool Expr::tryEvaluate(APValue &Result, ASTContext &Ctx) const {
+bool Expr::Evaluate(APValue &Result, ASTContext &Ctx) const {
EvalInfo Info(Ctx);
if (getType()->isIntegerType()) {
llvm::APSInt sInt(32);
return false;
}
-/// isEvaluatable - Call tryEvaluate to see if this expression can be constant
+/// isEvaluatable - Call Evaluate to see if this expression can be constant
/// folded, but discard the result.
bool Expr::isEvaluatable(ASTContext &Ctx) const {
APValue V;
- return tryEvaluate(V, Ctx);
+ return Evaluate(V, Ctx);
}
RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
// See if we can constant fold this builtin. If so, don't emit it at all.
APValue Result;
- if (E->tryEvaluate(Result, CGM.getContext())) {
+ if (E->Evaluate(Result, CGM.getContext())) {
if (Result.isInt())
return RValue::get(llvm::ConstantInt::get(Result.getInt()));
assert(Result.isFloat() && "Unsupported constant type");
llvm::Constant *VisitCallExpr(const CallExpr *E) {
APValue Result;
- if (E->tryEvaluate(Result, CGM.getContext())) {
+ if (E->Evaluate(Result, CGM.getContext())) {
if (Result.isInt())
return llvm::ConstantInt::get(Result.getInt());
if (Result.isFloat())
#ifdef USE_TRY_EVALUATE
APValue V;
- if (E->tryEvaluate(V, Context)) {
+ if (E->Evaluate(V, Context)) {
// FIXME: Assert that the value doesn't have any side effects.
switch (V.getKind()) {
default: assert(0 && "unhandled value kind!");
// FIXME: Rename and handle conversion of other evaluatable things
// to bool.
- if (!Cond->tryEvaluate(V, getContext()) || !V.isInt())
+ if (!Cond->Evaluate(V, getContext()) || !V.isInt())
return 0; // Not foldable or not integer.
if (CodeGenFunction::ContainsLabel(Cond))
// specified arm of the conditional to be a constant. This is a horrible
// hack, but is require by real world code that uses __builtin_constant_p.
APValue Val;
- if (!Exp->getCond()->tryEvaluate(Val, Context)) {
- // If the tryEvaluate couldn't fold it, CheckArithmeticConstantExpression
+ if (!Exp->getCond()->Evaluate(Val, Context)) {
+ // If Evaluate couldn't fold it, CheckArithmeticConstantExpression
// won't be able to either. Use it to emit the diagnostic though.
bool Res = CheckArithmeticConstantExpression(Exp->getCond());
- assert(Res && "tryEvaluate couldn't evaluate this constant?");
+ assert(Res && "Evaluate couldn't evaluate this constant?");
return Res;
}
APValue Result;
if (!VLATy->getSizeExpr() ||
- !VLATy->getSizeExpr()->tryEvaluate(Result, Context))
+ !VLATy->getSizeExpr()->Evaluate(Result, Context))
return QualType();
assert(Result.isInt() && "Size expressions must be integers!");