blob: 1f43e44dad8121afd23b556ee5043087c1f59beb [file] [log] [blame]
Chris Lattnerb542afe2008-07-11 19:10:17 +00001//===--- ExprConstant.cpp - Expression Constant Evaluator -----------------===//
Anders Carlssonc44eec62008-07-03 04:20:39 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Expr constant evaluator.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/AST/APValue.h"
15#include "clang/AST/ASTContext.h"
16#include "clang/AST/Expr.h"
Seo Sanghyeon0fe52e12008-07-08 07:23:12 +000017#include "clang/AST/StmtVisitor.h"
Anders Carlsson06a36752008-07-08 05:49:43 +000018#include "clang/Basic/TargetInfo.h"
Anders Carlssonc754aa62008-07-08 05:13:58 +000019#include "llvm/Support/Compiler.h"
Anders Carlssonc44eec62008-07-03 04:20:39 +000020using namespace clang;
Chris Lattnerf5eeb052008-07-11 18:11:29 +000021using llvm::APSInt;
Anders Carlssonc44eec62008-07-03 04:20:39 +000022
Anders Carlssonc754aa62008-07-08 05:13:58 +000023#define USE_NEW_EVALUATOR 0
Anders Carlssonc44eec62008-07-03 04:20:39 +000024
Chris Lattnerf5eeb052008-07-11 18:11:29 +000025static bool CalcFakeICEVal(const Expr *Expr,
26 llvm::APSInt &Result,
27 ASTContext &Context) {
Anders Carlssonc44eec62008-07-03 04:20:39 +000028 // Calculate the value of an expression that has a calculatable
29 // value, but isn't an ICE. Currently, this only supports
30 // a very narrow set of extensions, but it can be expanded if needed.
31 if (const ParenExpr *PE = dyn_cast<ParenExpr>(Expr))
32 return CalcFakeICEVal(PE->getSubExpr(), Result, Context);
33
34 if (const CastExpr *CE = dyn_cast<CastExpr>(Expr)) {
35 QualType CETy = CE->getType();
36 if ((CETy->isIntegralType() && !CETy->isBooleanType()) ||
37 CETy->isPointerType()) {
38 if (CalcFakeICEVal(CE->getSubExpr(), Result, Context)) {
39 Result.extOrTrunc(Context.getTypeSize(CETy));
40 // FIXME: This assumes pointers are signed.
41 Result.setIsSigned(CETy->isSignedIntegerType() ||
42 CETy->isPointerType());
43 return true;
44 }
45 }
46 }
47
48 if (Expr->getType()->isIntegralType())
49 return Expr->isIntegerConstantExpr(Result, Context);
50
51 return false;
52}
53
Chris Lattnerf5eeb052008-07-11 18:11:29 +000054static bool EvaluatePointer(const Expr *E, APValue &Result, ASTContext &Ctx);
55static bool EvaluateInteger(const Expr *E, APSInt &Result, ASTContext &Ctx);
56
57
58//===----------------------------------------------------------------------===//
59// Pointer Evaluation
60//===----------------------------------------------------------------------===//
61
Anders Carlssonc754aa62008-07-08 05:13:58 +000062namespace {
Anders Carlsson2bad1682008-07-08 14:30:00 +000063class VISIBILITY_HIDDEN PointerExprEvaluator
64 : public StmtVisitor<PointerExprEvaluator, APValue> {
65 ASTContext &Ctx;
Anders Carlsson2bad1682008-07-08 14:30:00 +000066public:
Anders Carlsson2bad1682008-07-08 14:30:00 +000067
Chris Lattnerf5eeb052008-07-11 18:11:29 +000068 PointerExprEvaluator(ASTContext &ctx) : Ctx(ctx) {}
69
Anders Carlsson2bad1682008-07-08 14:30:00 +000070 APValue VisitStmt(Stmt *S) {
71 // FIXME: Remove this when we support more expressions.
Anders Carlsson650c92f2008-07-08 15:34:11 +000072 printf("Unhandled pointer statement\n");
Anders Carlsson2bad1682008-07-08 14:30:00 +000073 S->dump();
74 return APValue();
75 }
76
77 APValue VisitParenExpr(ParenExpr *E) { return Visit(E->getSubExpr()); }
78
Anders Carlsson650c92f2008-07-08 15:34:11 +000079 APValue VisitBinaryOperator(const BinaryOperator *E);
80 APValue VisitCastExpr(const CastExpr* E);
Anders Carlsson650c92f2008-07-08 15:34:11 +000081};
Chris Lattnerf5eeb052008-07-11 18:11:29 +000082} // end anonymous namespace
Anders Carlsson650c92f2008-07-08 15:34:11 +000083
Chris Lattnerf5eeb052008-07-11 18:11:29 +000084static bool EvaluatePointer(const Expr* E, APValue& Result, ASTContext &Ctx) {
85 if (!E->getType()->isPointerType())
86 return false;
87 Result = PointerExprEvaluator(Ctx).Visit(const_cast<Expr*>(E));
88 return Result.isLValue();
89}
90
91APValue PointerExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
92 if (E->getOpcode() != BinaryOperator::Add &&
93 E->getOpcode() != BinaryOperator::Sub)
94 return APValue();
95
96 const Expr *PExp = E->getLHS();
97 const Expr *IExp = E->getRHS();
98 if (IExp->getType()->isPointerType())
99 std::swap(PExp, IExp);
100
101 APValue ResultLValue;
102 if (!EvaluatePointer(PExp, ResultLValue, Ctx))
103 return APValue();
104
105 llvm::APSInt AdditionalOffset(32);
106 if (!EvaluateInteger(IExp, AdditionalOffset, Ctx))
107 return APValue();
108
109 uint64_t Offset = ResultLValue.getLValueOffset();
110 if (E->getOpcode() == BinaryOperator::Add)
111 Offset += AdditionalOffset.getZExtValue();
112 else
113 Offset -= AdditionalOffset.getZExtValue();
114
115 return APValue(ResultLValue.getLValueBase(), Offset);
116}
117
118
Chris Lattnerb542afe2008-07-11 19:10:17 +0000119APValue PointerExprEvaluator::VisitCastExpr(const CastExpr* E) {
Chris Lattnerf5eeb052008-07-11 18:11:29 +0000120 const Expr* SubExpr = E->getSubExpr();
121
122 // Check for pointer->pointer cast
123 if (SubExpr->getType()->isPointerType()) {
124 APValue Result;
125 if (EvaluatePointer(SubExpr, Result, Ctx))
126 return Result;
127 return APValue();
128 }
129
130 if (SubExpr->getType()->isArithmeticType()) {
131 llvm::APSInt Result(32);
132 if (EvaluateInteger(SubExpr, Result, Ctx)) {
133 Result.extOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(E->getType())));
134 return APValue(0, Result.getZExtValue());
135 }
136 }
137
138 assert(0 && "Unhandled cast");
139 return APValue();
140}
141
142
143//===----------------------------------------------------------------------===//
144// Integer Evaluation
145//===----------------------------------------------------------------------===//
Chris Lattnerf5eeb052008-07-11 18:11:29 +0000146
147namespace {
Anders Carlssonc754aa62008-07-08 05:13:58 +0000148class VISIBILITY_HIDDEN IntExprEvaluator
Chris Lattnerb542afe2008-07-11 19:10:17 +0000149 : public StmtVisitor<IntExprEvaluator, bool> {
Anders Carlssonc754aa62008-07-08 05:13:58 +0000150 ASTContext &Ctx;
Chris Lattnerb542afe2008-07-11 19:10:17 +0000151 APSInt &Result;
Anders Carlssonc754aa62008-07-08 05:13:58 +0000152public:
Chris Lattnerb542afe2008-07-11 19:10:17 +0000153 IntExprEvaluator(ASTContext &ctx, APSInt &result) : Ctx(ctx), Result(result){}
Chris Lattnerf5eeb052008-07-11 18:11:29 +0000154
Chris Lattner7a767782008-07-11 19:24:49 +0000155 unsigned getIntTypeSizeInBits(QualType T) const {
156 return (unsigned)Ctx.getTypeSize(T);
157 }
158
Anders Carlssonc754aa62008-07-08 05:13:58 +0000159 //===--------------------------------------------------------------------===//
160 // Visitor Methods
161 //===--------------------------------------------------------------------===//
Chris Lattner7a767782008-07-11 19:24:49 +0000162
Chris Lattnerb542afe2008-07-11 19:10:17 +0000163 bool VisitStmt(Stmt *S) {
Anders Carlssonc754aa62008-07-08 05:13:58 +0000164 // FIXME: Remove this when we support more expressions.
Anders Carlsson650c92f2008-07-08 15:34:11 +0000165 printf("unhandled int expression");
Anders Carlssonc754aa62008-07-08 05:13:58 +0000166 S->dump();
Chris Lattnerb542afe2008-07-11 19:10:17 +0000167 return false;
Anders Carlssonc754aa62008-07-08 05:13:58 +0000168 }
169
Chris Lattnerb542afe2008-07-11 19:10:17 +0000170 bool VisitParenExpr(ParenExpr *E) { return Visit(E->getSubExpr()); }
Anders Carlssonc754aa62008-07-08 05:13:58 +0000171
Chris Lattnerb542afe2008-07-11 19:10:17 +0000172 bool VisitBinaryOperator(const BinaryOperator *E);
173 bool VisitUnaryOperator(const UnaryOperator *E);
Anders Carlsson06a36752008-07-08 05:49:43 +0000174
Chris Lattnerb542afe2008-07-11 19:10:17 +0000175 bool VisitCastExpr(const CastExpr* E) {
Anders Carlsson650c92f2008-07-08 15:34:11 +0000176 return HandleCast(E->getSubExpr(), E->getType());
177 }
Chris Lattnerb542afe2008-07-11 19:10:17 +0000178 bool VisitImplicitCastExpr(const ImplicitCastExpr* E) {
Anders Carlsson650c92f2008-07-08 15:34:11 +0000179 return HandleCast(E->getSubExpr(), E->getType());
180 }
Chris Lattnerfcee0012008-07-11 21:24:13 +0000181 bool VisitSizeOfAlignOfTypeExpr(const SizeOfAlignOfTypeExpr *E) {
182 return EvaluateSizeAlignOf(E->isSizeOf(),E->getArgumentType(),E->getType());
183 }
Anders Carlsson650c92f2008-07-08 15:34:11 +0000184
Chris Lattnerb542afe2008-07-11 19:10:17 +0000185 bool VisitIntegerLiteral(const IntegerLiteral *E) {
Anders Carlsson650c92f2008-07-08 15:34:11 +0000186 Result = E->getValue();
Chris Lattnerb542afe2008-07-11 19:10:17 +0000187 return true;
Anders Carlsson650c92f2008-07-08 15:34:11 +0000188 }
Chris Lattnerfcee0012008-07-11 21:24:13 +0000189private:
190 bool HandleCast(const Expr* SubExpr, QualType DestType);
191 bool EvaluateSizeAlignOf(bool isSizeOf, QualType SrcTy, QualType DstTy);
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000192};
Chris Lattnerf5eeb052008-07-11 18:11:29 +0000193} // end anonymous namespace
Anders Carlsson650c92f2008-07-08 15:34:11 +0000194
Chris Lattnerf5eeb052008-07-11 18:11:29 +0000195static bool EvaluateInteger(const Expr* E, APSInt &Result, ASTContext &Ctx) {
Chris Lattnerb542afe2008-07-11 19:10:17 +0000196 return IntExprEvaluator(Ctx, Result).Visit(const_cast<Expr*>(E));
Anders Carlsson650c92f2008-07-08 15:34:11 +0000197}
Anders Carlsson650c92f2008-07-08 15:34:11 +0000198
Anders Carlsson650c92f2008-07-08 15:34:11 +0000199
Chris Lattnerb542afe2008-07-11 19:10:17 +0000200bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000201 // The LHS of a constant expr is always evaluated and needed.
Chris Lattnerb542afe2008-07-11 19:10:17 +0000202 if (!Visit(E->getLHS()))
203 return false;
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000204
205 llvm::APSInt RHS(32);
Chris Lattnerf5eeb052008-07-11 18:11:29 +0000206 if (!EvaluateInteger(E->getRHS(), RHS, Ctx))
Chris Lattnerb542afe2008-07-11 19:10:17 +0000207 return false;
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000208
209 switch (E->getOpcode()) {
210 default:
Chris Lattnerb542afe2008-07-11 19:10:17 +0000211 return false;
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000212 case BinaryOperator::Mul:
213 Result *= RHS;
214 break;
215 case BinaryOperator::Div:
216 if (RHS == 0)
Chris Lattnerb542afe2008-07-11 19:10:17 +0000217 return false;
218 Result /= RHS;
219 break;
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000220 case BinaryOperator::Rem:
221 if (RHS == 0)
Chris Lattnerb542afe2008-07-11 19:10:17 +0000222 return false;
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000223 Result %= RHS;
224 break;
225 case BinaryOperator::Add: Result += RHS; break;
226 case BinaryOperator::Sub: Result -= RHS; break;
Chris Lattnerac7cb602008-07-11 19:29:32 +0000227 case BinaryOperator::And: Result &= RHS; break;
228 case BinaryOperator::Xor: Result ^= RHS; break;
229 case BinaryOperator::Or: Result |= RHS; break;
230
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000231 case BinaryOperator::Shl:
Chris Lattnerb542afe2008-07-11 19:10:17 +0000232 Result <<= (unsigned)RHS.getLimitedValue(Result.getBitWidth()-1);
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000233 break;
234 case BinaryOperator::Shr:
Chris Lattnerb542afe2008-07-11 19:10:17 +0000235 Result >>= (unsigned)RHS.getLimitedValue(Result.getBitWidth()-1);
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000236 break;
Chris Lattnerb542afe2008-07-11 19:10:17 +0000237
Chris Lattnerac7cb602008-07-11 19:29:32 +0000238 case BinaryOperator::LT:
239 Result = Result < RHS;
240 Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
241 break;
242 case BinaryOperator::GT:
243 Result = Result > RHS;
244 Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
245 break;
246 case BinaryOperator::LE:
247 Result = Result <= RHS;
248 Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
249 break;
250 case BinaryOperator::GE:
251 Result = Result >= RHS;
252 Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
253 break;
254 case BinaryOperator::EQ:
255 Result = Result == RHS;
256 Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
257 break;
258 case BinaryOperator::NE:
259 Result = Result != RHS;
260 Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
261 break;
Anders Carlsson06a36752008-07-08 05:49:43 +0000262
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000263 case BinaryOperator::Comma:
264 // C99 6.6p3: "shall not contain assignment, ..., or comma operators,
265 // *except* when they are contained within a subexpression that is not
266 // evaluated". Note that Assignment can never happen due to constraints
267 // on the LHS subexpr, so we don't need to check it here.
268 // FIXME: Need to come up with an efficient way to deal with the C99
269 // rules on evaluation while still evaluating this. Maybe a
270 // "evaluated comma" out parameter?
Chris Lattnerb542afe2008-07-11 19:10:17 +0000271 return false;
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000272 }
273
274 Result.setIsUnsigned(E->getType()->isUnsignedIntegerType());
Chris Lattnerb542afe2008-07-11 19:10:17 +0000275 return true;
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000276}
277
Chris Lattnerfcee0012008-07-11 21:24:13 +0000278/// EvaluateSizeAlignOf - Evaluate sizeof(SrcTy) or alignof(SrcTy) with a result
279/// as a DstTy type.
280bool IntExprEvaluator::EvaluateSizeAlignOf(bool isSizeOf, QualType SrcTy,
281 QualType DstTy) {
282 // Return the result in the right width.
283 Result.zextOrTrunc(getIntTypeSizeInBits(DstTy));
284 Result.setIsUnsigned(DstTy->isUnsignedIntegerType());
285
286 // sizeof(void) and __alignof__(void) = 1 as a gcc extension.
287 if (SrcTy->isVoidType())
288 Result = 1;
289
290 // sizeof(vla) is not a constantexpr: C99 6.5.3.4p2.
291 if (!SrcTy->isConstantSizeType()) {
292 // FIXME: Should we attempt to evaluate this?
293 return false;
294 }
295
296 // GCC extension: sizeof(function) = 1.
297 if (SrcTy->isFunctionType()) {
298 // FIXME: AlignOf shouldn't be unconditionally 4!
299 Result = isSizeOf ? 1 : 4;
300 return true;
301 }
302
303 // Get information about the size or align.
304 unsigned CharSize = Ctx.Target.getCharWidth();
305 if (isSizeOf)
306 Result = getIntTypeSizeInBits(SrcTy) / CharSize;
307 else
308 Result = Ctx.getTypeAlign(SrcTy) / CharSize;
309 return true;
310}
311
Chris Lattnerb542afe2008-07-11 19:10:17 +0000312bool IntExprEvaluator::VisitUnaryOperator(const UnaryOperator *E) {
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000313 if (E->isOffsetOfOp())
314 Result = E->evaluateOffsetOf(Ctx);
Chris Lattnerfcee0012008-07-11 21:24:13 +0000315 else if (E->isSizeOfAlignOfOp())
316 return EvaluateSizeAlignOf(E->getOpcode() == UnaryOperator::SizeOf,
317 E->getSubExpr()->getType(), E->getType());
318 else {
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000319 // Get the operand value. If this is sizeof/alignof, do not evalute the
320 // operand. This affects C99 6.6p3.
Chris Lattnerf5eeb052008-07-11 18:11:29 +0000321 if (!EvaluateInteger(E->getSubExpr(), Result, Ctx))
Chris Lattnerb542afe2008-07-11 19:10:17 +0000322 return false;
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000323
Anders Carlsson06a36752008-07-08 05:49:43 +0000324 switch (E->getOpcode()) {
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000325 // Address, indirect, pre/post inc/dec, etc are not valid constant exprs.
326 // See C99 6.6p3.
Anders Carlsson06a36752008-07-08 05:49:43 +0000327 default:
Chris Lattnerb542afe2008-07-11 19:10:17 +0000328 return false;
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000329 case UnaryOperator::LNot: {
330 bool Val = Result == 0;
Chris Lattner7a767782008-07-11 19:24:49 +0000331 Result.zextOrTrunc(getIntTypeSizeInBits(E->getType()));
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000332 Result = Val;
Anders Carlsson06a36752008-07-08 05:49:43 +0000333 break;
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000334 }
Chris Lattnerac7cb602008-07-11 19:29:32 +0000335 case UnaryOperator::Extension:
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000336 case UnaryOperator::Plus:
Chris Lattnerac7cb602008-07-11 19:29:32 +0000337 // The result is always just the subexpr
Anders Carlsson06a36752008-07-08 05:49:43 +0000338 break;
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000339 case UnaryOperator::Minus:
340 Result = -Result;
Anders Carlsson06a36752008-07-08 05:49:43 +0000341 break;
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000342 case UnaryOperator::Not:
343 Result = ~Result;
Anders Carlsson06a36752008-07-08 05:49:43 +0000344 break;
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000345 }
346 }
347
348 Result.setIsUnsigned(E->getType()->isUnsignedIntegerType());
Chris Lattnerb542afe2008-07-11 19:10:17 +0000349 return true;
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000350}
351
Chris Lattnerb542afe2008-07-11 19:10:17 +0000352bool IntExprEvaluator::HandleCast(const Expr* SubExpr, QualType DestType) {
Chris Lattner7a767782008-07-11 19:24:49 +0000353 unsigned DestWidth = getIntTypeSizeInBits(DestType);
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000354
355 // Handle simple integer->integer casts.
356 if (SubExpr->getType()->isIntegerType()) {
Chris Lattnerf5eeb052008-07-11 18:11:29 +0000357 if (!EvaluateInteger(SubExpr, Result, Ctx))
Chris Lattnerb542afe2008-07-11 19:10:17 +0000358 return false;
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000359
360 // Figure out if this is a truncate, extend or noop cast.
361 // If the input is signed, do a sign extend, noop, or truncate.
362 if (DestType->isBooleanType()) {
363 // Conversion to bool compares against zero.
364 Result = Result != 0;
365 Result.zextOrTrunc(DestWidth);
Chris Lattner7a767782008-07-11 19:24:49 +0000366 } else
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000367 Result.extOrTrunc(DestWidth);
368 } else if (SubExpr->getType()->isPointerType()) {
369 APValue LV;
Chris Lattnerf5eeb052008-07-11 18:11:29 +0000370 if (!EvaluatePointer(SubExpr, LV, Ctx))
Chris Lattnerb542afe2008-07-11 19:10:17 +0000371 return false;
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000372 if (LV.getLValueBase())
Chris Lattnerb542afe2008-07-11 19:10:17 +0000373 return false;
Anders Carlsson06a36752008-07-08 05:49:43 +0000374
Anders Carlsson559e56b2008-07-08 16:49:00 +0000375 Result.extOrTrunc(DestWidth);
376 Result = LV.getLValueOffset();
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000377 } else {
378 assert(0 && "Unhandled cast!");
Anders Carlsson2bad1682008-07-08 14:30:00 +0000379 }
380
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000381 Result.setIsUnsigned(DestType->isUnsignedIntegerType());
Chris Lattnerb542afe2008-07-11 19:10:17 +0000382 return true;
Anders Carlssona25ae3d2008-07-08 14:35:21 +0000383}
Anders Carlsson2bad1682008-07-08 14:30:00 +0000384
Chris Lattnerf5eeb052008-07-11 18:11:29 +0000385//===----------------------------------------------------------------------===//
386// Top level TryEvaluate.
387//===----------------------------------------------------------------------===//
388
Chris Lattnerb542afe2008-07-11 19:10:17 +0000389bool Expr::tryEvaluate(APValue &Result, ASTContext &Ctx) const {
Chris Lattnercf0f51d2008-07-11 19:19:21 +0000390 llvm::APSInt sInt(32);
Anders Carlssonc754aa62008-07-08 05:13:58 +0000391#if USE_NEW_EVALUATOR
Anders Carlsson06a36752008-07-08 05:49:43 +0000392 if (getType()->isIntegerType()) {
Chris Lattnerb542afe2008-07-11 19:10:17 +0000393 if (EvaluateInteger(this, sInt, Ctx)) {
Anders Carlsson06a36752008-07-08 05:49:43 +0000394 Result = APValue(sInt);
395 return true;
396 }
397 } else
Anders Carlssonc754aa62008-07-08 05:13:58 +0000398 return false;
399
400#else
Anders Carlssonc44eec62008-07-03 04:20:39 +0000401 if (CalcFakeICEVal(this, sInt, Ctx)) {
402 Result = APValue(sInt);
403 return true;
404 }
Anders Carlssonc754aa62008-07-08 05:13:58 +0000405#endif
Anders Carlssonc44eec62008-07-03 04:20:39 +0000406
407 return false;
408}