/// 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
+ /// 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;
/// hasGlobalStorage - Return true if this expression has static storage
return Error(E->getLocStart(), diag::err_expr_not_constant);
}
-
bool IntExprEvaluator::VisitCallExpr(const CallExpr *E) {
Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
- // __builtin_type_compatible_p is a constant.
- if (E->isBuiltinClassifyType(Result))
- return true;
- return Error(E->getLocStart(), diag::err_expr_not_constant);
+ switch (E->isBuiltinCall()) {
+ default:
+ return Error(E->getLocStart(), diag::err_expr_not_constant);
+ case Builtin::BI__builtin_classify_type:
+ // __builtin_type_compatible_p is a constant. Return its value.
+ E->isBuiltinClassifyType(Result);
+ return true;
+
+ case Builtin::BI__builtin_constant_p: {
+ // __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);
+ return true;
+ }
+ }
}
bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
}
bool VisitParenExpr(ParenExpr *E) { return Visit(E->getSubExpr()); }
+ bool VisitCallExpr(const CallExpr *E);
bool VisitBinaryOperator(const BinaryOperator *E);
bool VisitFloatingLiteral(const FloatingLiteral *E);
return FloatExprEvaluator(Info, Result).Visit(const_cast<Expr*>(E));
}
+bool FloatExprEvaluator::VisitCallExpr(const CallExpr *E) {
+ //Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
+
+ switch (E->isBuiltinCall()) {
+ case Builtin::BI__builtin_huge_val:
+ case Builtin::BI__builtin_huge_valf:
+ case Builtin::BI__builtin_huge_vall:
+ case Builtin::BI__builtin_inf:
+ case Builtin::BI__builtin_inff:
+ case Builtin::BI__builtin_infl:
+ // FIXME: Implement me.
+ default: return false;
+ }
+}
+
+
bool FloatExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
// FIXME: Diagnostics? I really don't understand how the warnings
// and errors are supposed to work.
// Top level TryEvaluate.
//===----------------------------------------------------------------------===//
+/// tryEvaluate - 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 {
EvalInfo Info(Ctx);
if (getType()->isIntegerType()) {