blob: becce2a6222ace4f95e87a29d1d1fdfd58e223ad [file] [log] [blame]
Chris Lattner4b009652007-07-25 00:24:17 +00001//===--- Expr.cpp - Expression AST Node Implementation --------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner959e5be2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner4b009652007-07-25 00:24:17 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Expr class and subclasses.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/AST/Expr.h"
15#include "clang/AST/ASTContext.h"
16#include "clang/AST/StmtVisitor.h"
Chris Lattner2fd1c652007-10-07 08:58:51 +000017#include "clang/Basic/IdentifierTable.h"
Chris Lattnerd9ffbc92007-11-27 18:22:04 +000018#include "clang/Basic/TargetInfo.h"
Chris Lattner4b009652007-07-25 00:24:17 +000019using namespace clang;
20
21//===----------------------------------------------------------------------===//
22// Primary Expressions.
23//===----------------------------------------------------------------------===//
24
25StringLiteral::StringLiteral(const char *strData, unsigned byteLength,
26 bool Wide, QualType t, SourceLocation firstLoc,
27 SourceLocation lastLoc) :
28 Expr(StringLiteralClass, t) {
29 // OPTIMIZE: could allocate this appended to the StringLiteral.
30 char *AStrData = new char[byteLength];
31 memcpy(AStrData, strData, byteLength);
32 StrData = AStrData;
33 ByteLength = byteLength;
34 IsWide = Wide;
35 firstTokLoc = firstLoc;
36 lastTokLoc = lastLoc;
37}
38
39StringLiteral::~StringLiteral() {
40 delete[] StrData;
41}
42
43bool UnaryOperator::isPostfix(Opcode Op) {
44 switch (Op) {
45 case PostInc:
46 case PostDec:
47 return true;
48 default:
49 return false;
50 }
51}
52
53/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
54/// corresponds to, e.g. "sizeof" or "[pre]++".
55const char *UnaryOperator::getOpcodeStr(Opcode Op) {
56 switch (Op) {
57 default: assert(0 && "Unknown unary operator");
58 case PostInc: return "++";
59 case PostDec: return "--";
60 case PreInc: return "++";
61 case PreDec: return "--";
62 case AddrOf: return "&";
63 case Deref: return "*";
64 case Plus: return "+";
65 case Minus: return "-";
66 case Not: return "~";
67 case LNot: return "!";
68 case Real: return "__real";
69 case Imag: return "__imag";
70 case SizeOf: return "sizeof";
71 case AlignOf: return "alignof";
72 case Extension: return "__extension__";
Chris Lattner0d9bcea2007-08-30 17:45:32 +000073 case OffsetOf: return "__builtin_offsetof";
Chris Lattner4b009652007-07-25 00:24:17 +000074 }
75}
76
77//===----------------------------------------------------------------------===//
78// Postfix Operators.
79//===----------------------------------------------------------------------===//
80
Nate Begeman9f3bfb72008-01-17 17:46:27 +000081
Chris Lattner4b009652007-07-25 00:24:17 +000082CallExpr::CallExpr(Expr *fn, Expr **args, unsigned numargs, QualType t,
83 SourceLocation rparenloc)
Ted Kremeneke4acb9c2007-08-24 18:13:47 +000084 : Expr(CallExprClass, t), NumArgs(numargs) {
85 SubExprs = new Expr*[numargs+1];
86 SubExprs[FN] = fn;
Chris Lattner4b009652007-07-25 00:24:17 +000087 for (unsigned i = 0; i != numargs; ++i)
Ted Kremeneke4acb9c2007-08-24 18:13:47 +000088 SubExprs[i+ARGS_START] = args[i];
Chris Lattner4b009652007-07-25 00:24:17 +000089 RParenLoc = rparenloc;
90}
91
Chris Lattnerc257c0d2007-12-28 05:25:02 +000092/// setNumArgs - This changes the number of arguments present in this call.
93/// Any orphaned expressions are deleted by this, and any new operands are set
94/// to null.
95void CallExpr::setNumArgs(unsigned NumArgs) {
96 // No change, just return.
97 if (NumArgs == getNumArgs()) return;
98
99 // If shrinking # arguments, just delete the extras and forgot them.
100 if (NumArgs < getNumArgs()) {
101 for (unsigned i = NumArgs, e = getNumArgs(); i != e; ++i)
102 delete getArg(i);
103 this->NumArgs = NumArgs;
104 return;
105 }
106
107 // Otherwise, we are growing the # arguments. New an bigger argument array.
108 Expr **NewSubExprs = new Expr*[NumArgs+1];
109 // Copy over args.
110 for (unsigned i = 0; i != getNumArgs()+ARGS_START; ++i)
111 NewSubExprs[i] = SubExprs[i];
112 // Null out new args.
113 for (unsigned i = getNumArgs()+ARGS_START; i != NumArgs+ARGS_START; ++i)
114 NewSubExprs[i] = 0;
115
116 delete[] SubExprs;
117 SubExprs = NewSubExprs;
118 this->NumArgs = NumArgs;
119}
120
121
Steve Naroff8d3b1702007-08-08 22:15:55 +0000122bool CallExpr::isBuiltinClassifyType(llvm::APSInt &Result) const {
123 // The following enum mimics gcc's internal "typeclass.h" file.
124 enum gcc_type_class {
125 no_type_class = -1,
126 void_type_class, integer_type_class, char_type_class,
127 enumeral_type_class, boolean_type_class,
128 pointer_type_class, reference_type_class, offset_type_class,
129 real_type_class, complex_type_class,
130 function_type_class, method_type_class,
131 record_type_class, union_type_class,
132 array_type_class, string_type_class,
133 lang_type_class
134 };
135 Result.setIsSigned(true);
136
137 // All simple function calls (e.g. func()) are implicitly cast to pointer to
138 // function. As a result, we try and obtain the DeclRefExpr from the
139 // ImplicitCastExpr.
140 const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee());
141 if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()).
142 return false;
143 const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr());
144 if (!DRE)
145 return false;
146
147 // We have a DeclRefExpr.
148 if (strcmp(DRE->getDecl()->getName(), "__builtin_classify_type") == 0) {
149 // If no argument was supplied, default to "no_type_class". This isn't
150 // ideal, however it's what gcc does.
151 Result = static_cast<uint64_t>(no_type_class);
152 if (NumArgs >= 1) {
153 QualType argType = getArg(0)->getType();
154
155 if (argType->isVoidType())
156 Result = void_type_class;
157 else if (argType->isEnumeralType())
158 Result = enumeral_type_class;
159 else if (argType->isBooleanType())
160 Result = boolean_type_class;
161 else if (argType->isCharType())
162 Result = string_type_class; // gcc doesn't appear to use char_type_class
163 else if (argType->isIntegerType())
164 Result = integer_type_class;
165 else if (argType->isPointerType())
166 Result = pointer_type_class;
167 else if (argType->isReferenceType())
168 Result = reference_type_class;
169 else if (argType->isRealType())
170 Result = real_type_class;
171 else if (argType->isComplexType())
172 Result = complex_type_class;
173 else if (argType->isFunctionType())
174 Result = function_type_class;
175 else if (argType->isStructureType())
176 Result = record_type_class;
177 else if (argType->isUnionType())
178 Result = union_type_class;
179 else if (argType->isArrayType())
180 Result = array_type_class;
181 else if (argType->isUnionType())
182 Result = union_type_class;
183 else // FIXME: offset_type_class, method_type_class, & lang_type_class?
Chris Lattner19b8f1a2007-11-08 17:56:40 +0000184 assert(0 && "CallExpr::isBuiltinClassifyType(): unimplemented type");
Steve Naroff8d3b1702007-08-08 22:15:55 +0000185 }
186 return true;
187 }
188 return false;
189}
190
Chris Lattner4b009652007-07-25 00:24:17 +0000191/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
192/// corresponds to, e.g. "<<=".
193const char *BinaryOperator::getOpcodeStr(Opcode Op) {
194 switch (Op) {
195 default: assert(0 && "Unknown binary operator");
196 case Mul: return "*";
197 case Div: return "/";
198 case Rem: return "%";
199 case Add: return "+";
200 case Sub: return "-";
201 case Shl: return "<<";
202 case Shr: return ">>";
203 case LT: return "<";
204 case GT: return ">";
205 case LE: return "<=";
206 case GE: return ">=";
207 case EQ: return "==";
208 case NE: return "!=";
209 case And: return "&";
210 case Xor: return "^";
211 case Or: return "|";
212 case LAnd: return "&&";
213 case LOr: return "||";
214 case Assign: return "=";
215 case MulAssign: return "*=";
216 case DivAssign: return "/=";
217 case RemAssign: return "%=";
218 case AddAssign: return "+=";
219 case SubAssign: return "-=";
220 case ShlAssign: return "<<=";
221 case ShrAssign: return ">>=";
222 case AndAssign: return "&=";
223 case XorAssign: return "^=";
224 case OrAssign: return "|=";
225 case Comma: return ",";
226 }
227}
228
Anders Carlsson762b7c72007-08-31 04:56:16 +0000229InitListExpr::InitListExpr(SourceLocation lbraceloc,
230 Expr **initexprs, unsigned numinits,
231 SourceLocation rbraceloc)
232 : Expr(InitListExprClass, QualType())
233 , NumInits(numinits)
234 , LBraceLoc(lbraceloc)
235 , RBraceLoc(rbraceloc)
236{
237 InitExprs = new Expr*[numinits];
238 for (unsigned i = 0; i != numinits; i++)
239 InitExprs[i] = initexprs[i];
240}
Chris Lattner4b009652007-07-25 00:24:17 +0000241
242//===----------------------------------------------------------------------===//
243// Generic Expression Routines
244//===----------------------------------------------------------------------===//
245
246/// hasLocalSideEffect - Return true if this immediate expression has side
247/// effects, not counting any sub-expressions.
248bool Expr::hasLocalSideEffect() const {
249 switch (getStmtClass()) {
250 default:
251 return false;
252 case ParenExprClass:
253 return cast<ParenExpr>(this)->getSubExpr()->hasLocalSideEffect();
254 case UnaryOperatorClass: {
255 const UnaryOperator *UO = cast<UnaryOperator>(this);
256
257 switch (UO->getOpcode()) {
258 default: return false;
259 case UnaryOperator::PostInc:
260 case UnaryOperator::PostDec:
261 case UnaryOperator::PreInc:
262 case UnaryOperator::PreDec:
263 return true; // ++/--
264
265 case UnaryOperator::Deref:
266 // Dereferencing a volatile pointer is a side-effect.
267 return getType().isVolatileQualified();
268 case UnaryOperator::Real:
269 case UnaryOperator::Imag:
270 // accessing a piece of a volatile complex is a side-effect.
271 return UO->getSubExpr()->getType().isVolatileQualified();
272
273 case UnaryOperator::Extension:
274 return UO->getSubExpr()->hasLocalSideEffect();
275 }
276 }
Chris Lattneref95ffd2007-12-01 06:07:34 +0000277 case BinaryOperatorClass: {
278 const BinaryOperator *BinOp = cast<BinaryOperator>(this);
279 // Consider comma to have side effects if the LHS and RHS both do.
280 if (BinOp->getOpcode() == BinaryOperator::Comma)
281 return BinOp->getLHS()->hasLocalSideEffect() &&
282 BinOp->getRHS()->hasLocalSideEffect();
283
284 return BinOp->isAssignmentOp();
285 }
Chris Lattner06078d22007-08-25 02:00:02 +0000286 case CompoundAssignOperatorClass:
Chris Lattner9c0da3b2007-08-25 01:55:00 +0000287 return true;
Chris Lattner4b009652007-07-25 00:24:17 +0000288
Fariborz Jahanian363c59b2007-12-01 19:58:28 +0000289 case ConditionalOperatorClass: {
290 const ConditionalOperator *Exp = cast<ConditionalOperator>(this);
291 return Exp->getCond()->hasLocalSideEffect()
292 || (Exp->getLHS() && Exp->getLHS()->hasLocalSideEffect())
293 || (Exp->getRHS() && Exp->getRHS()->hasLocalSideEffect());
294 }
295
Chris Lattner4b009652007-07-25 00:24:17 +0000296 case MemberExprClass:
297 case ArraySubscriptExprClass:
298 // If the base pointer or element is to a volatile pointer/field, accessing
299 // if is a side effect.
300 return getType().isVolatileQualified();
301
302 case CallExprClass:
303 // TODO: check attributes for pure/const. "void foo() { strlen("bar"); }"
304 // should warn.
305 return true;
Chris Lattner99f5f0b2007-09-26 22:06:30 +0000306 case ObjCMessageExprClass:
307 return true;
Chris Lattner4b009652007-07-25 00:24:17 +0000308
309 case CastExprClass:
310 // If this is a cast to void, check the operand. Otherwise, the result of
311 // the cast is unused.
312 if (getType()->isVoidType())
313 return cast<CastExpr>(this)->getSubExpr()->hasLocalSideEffect();
314 return false;
315 }
316}
317
318/// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or an
319/// incomplete type other than void. Nonarray expressions that can be lvalues:
320/// - name, where name must be a variable
321/// - e[i]
322/// - (e), where e must be an lvalue
323/// - e.name, where e must be an lvalue
324/// - e->name
325/// - *e, the type of e cannot be a function type
326/// - string-constant
Chris Lattner5bf72022007-10-30 22:53:42 +0000327/// - (__real__ e) and (__imag__ e) where e is an lvalue [GNU extension]
Chris Lattner4b009652007-07-25 00:24:17 +0000328/// - reference type [C++ [expr]]
329///
330Expr::isLvalueResult Expr::isLvalue() const {
331 // first, check the type (C99 6.3.2.1)
332 if (TR->isFunctionType()) // from isObjectType()
333 return LV_NotObjectType;
334
335 if (TR->isVoidType())
336 return LV_IncompleteVoidType;
337
338 if (TR->isReferenceType()) // C++ [expr]
339 return LV_Valid;
340
341 // the type looks fine, now check the expression
342 switch (getStmtClass()) {
343 case StringLiteralClass: // C99 6.5.1p4
Anders Carlsson9e933a22007-11-30 22:47:59 +0000344 return LV_Valid;
Chris Lattner4b009652007-07-25 00:24:17 +0000345 case ArraySubscriptExprClass: // C99 6.5.3p4 (e1[e2] == (*((e1)+(e2))))
346 // For vectors, make sure base is an lvalue (i.e. not a function call).
347 if (cast<ArraySubscriptExpr>(this)->getBase()->getType()->isVectorType())
348 return cast<ArraySubscriptExpr>(this)->getBase()->isLvalue();
349 return LV_Valid;
350 case DeclRefExprClass: // C99 6.5.1p2
351 if (isa<VarDecl>(cast<DeclRefExpr>(this)->getDecl()))
352 return LV_Valid;
353 break;
354 case MemberExprClass: { // C99 6.5.2.3p4
355 const MemberExpr *m = cast<MemberExpr>(this);
356 return m->isArrow() ? LV_Valid : m->getBase()->isLvalue();
357 }
Chris Lattner5bf72022007-10-30 22:53:42 +0000358 case UnaryOperatorClass:
Chris Lattner4b009652007-07-25 00:24:17 +0000359 if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Deref)
Chris Lattner5bf72022007-10-30 22:53:42 +0000360 return LV_Valid; // C99 6.5.3p4
361
362 if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Real ||
363 cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Imag)
364 return cast<UnaryOperator>(this)->getSubExpr()->isLvalue(); // GNU.
Chris Lattner4b009652007-07-25 00:24:17 +0000365 break;
366 case ParenExprClass: // C99 6.5.1p5
367 return cast<ParenExpr>(this)->getSubExpr()->isLvalue();
Steve Naroffc7c66532007-12-05 04:00:10 +0000368 case CompoundLiteralExprClass: // C99 6.5.2.5p5
369 return LV_Valid;
Chris Lattnera0d03a72007-08-03 17:31:20 +0000370 case OCUVectorElementExprClass:
371 if (cast<OCUVectorElementExpr>(this)->containsDuplicateElements())
Steve Naroffba67f692007-07-30 03:29:09 +0000372 return LV_DuplicateVectorComponents;
373 return LV_Valid;
Steve Naroff46f18f22007-11-12 14:34:27 +0000374 case ObjCIvarRefExprClass: // ObjC instance variables are lvalues.
375 return LV_Valid;
Chris Lattner7e637512008-01-12 08:14:25 +0000376 case PreDefinedExprClass:
377 return LV_Valid;
Chris Lattner4b009652007-07-25 00:24:17 +0000378 default:
379 break;
380 }
381 return LV_InvalidExpression;
382}
383
384/// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
385/// does not have an incomplete type, does not have a const-qualified type, and
386/// if it is a structure or union, does not have any member (including,
387/// recursively, any member or element of all contained aggregates or unions)
388/// with a const-qualified type.
389Expr::isModifiableLvalueResult Expr::isModifiableLvalue() const {
390 isLvalueResult lvalResult = isLvalue();
391
392 switch (lvalResult) {
393 case LV_Valid: break;
394 case LV_NotObjectType: return MLV_NotObjectType;
395 case LV_IncompleteVoidType: return MLV_IncompleteVoidType;
Steve Naroffba67f692007-07-30 03:29:09 +0000396 case LV_DuplicateVectorComponents: return MLV_DuplicateVectorComponents;
Chris Lattner4b009652007-07-25 00:24:17 +0000397 case LV_InvalidExpression: return MLV_InvalidExpression;
398 }
399 if (TR.isConstQualified())
400 return MLV_ConstQualified;
401 if (TR->isArrayType())
402 return MLV_ArrayType;
403 if (TR->isIncompleteType())
404 return MLV_IncompleteType;
405
406 if (const RecordType *r = dyn_cast<RecordType>(TR.getCanonicalType())) {
407 if (r->hasConstFields())
408 return MLV_ConstQualified;
409 }
410 return MLV_Valid;
411}
412
Chris Lattner743ec372007-11-27 21:35:27 +0000413/// hasStaticStorage - Return true if this expression has static storage
414/// duration. This means that the address of this expression is a link-time
415/// constant.
Chris Lattnerba3ddb22007-11-13 18:05:45 +0000416bool Expr::hasStaticStorage() const {
417 switch (getStmtClass()) {
418 default:
419 return false;
Chris Lattner743ec372007-11-27 21:35:27 +0000420 case ParenExprClass:
421 return cast<ParenExpr>(this)->getSubExpr()->hasStaticStorage();
422 case ImplicitCastExprClass:
423 return cast<ImplicitCastExpr>(this)->getSubExpr()->hasStaticStorage();
Steve Naroffbe37fc02008-01-14 18:19:28 +0000424 case CompoundLiteralExprClass:
425 return cast<CompoundLiteralExpr>(this)->isFileScope();
Chris Lattnerba3ddb22007-11-13 18:05:45 +0000426 case DeclRefExprClass: {
427 const Decl *D = cast<DeclRefExpr>(this)->getDecl();
428 if (const VarDecl *VD = dyn_cast<VarDecl>(D))
429 return VD->hasStaticStorage();
430 return false;
431 }
Chris Lattnerdb586bf2007-11-28 04:30:09 +0000432 case MemberExprClass: {
Chris Lattnerba3ddb22007-11-13 18:05:45 +0000433 const MemberExpr *M = cast<MemberExpr>(this);
434 return !M->isArrow() && M->getBase()->hasStaticStorage();
Chris Lattnerdb586bf2007-11-28 04:30:09 +0000435 }
Chris Lattner743ec372007-11-27 21:35:27 +0000436 case ArraySubscriptExprClass:
437 return cast<ArraySubscriptExpr>(this)->getBase()->hasStaticStorage();
Chris Lattner7e637512008-01-12 08:14:25 +0000438 case PreDefinedExprClass:
439 return true;
Chris Lattnerba3ddb22007-11-13 18:05:45 +0000440 }
441}
442
Ted Kremenek87e30c52008-01-17 16:57:34 +0000443Expr* Expr::IgnoreParens() {
444 Expr* E = this;
445 while (ParenExpr* P = dyn_cast<ParenExpr>(E))
446 E = P->getSubExpr();
447
448 return E;
449}
450
Steve Naroff7c9d72d2007-09-02 20:30:18 +0000451bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const {
Steve Naroff7c9d72d2007-09-02 20:30:18 +0000452 switch (getStmtClass()) {
453 default:
454 if (Loc) *Loc = getLocStart();
455 return false;
456 case ParenExprClass:
457 return cast<ParenExpr>(this)->getSubExpr()->isConstantExpr(Ctx, Loc);
458 case StringLiteralClass:
Steve Naroff4fdea132007-11-09 15:00:03 +0000459 case ObjCStringLiteralClass:
Steve Naroff7c9d72d2007-09-02 20:30:18 +0000460 case FloatingLiteralClass:
461 case IntegerLiteralClass:
462 case CharacterLiteralClass:
463 case ImaginaryLiteralClass:
Anders Carlsson855d78d2007-10-17 00:52:43 +0000464 case TypesCompatibleExprClass:
465 case CXXBoolLiteralExprClass:
Chris Lattner06db6132007-10-18 00:20:32 +0000466 return true;
Steve Naroff7c9d72d2007-09-02 20:30:18 +0000467 case CallExprClass: {
468 const CallExpr *CE = cast<CallExpr>(this);
469 llvm::APSInt Result(32);
Hartmut Kaiser38af7012007-09-16 21:35:35 +0000470 Result.zextOrTrunc(
471 static_cast<uint32_t>(Ctx.getTypeSize(getType(), CE->getLocStart())));
Steve Naroff7c9d72d2007-09-02 20:30:18 +0000472 if (CE->isBuiltinClassifyType(Result))
Chris Lattner06db6132007-10-18 00:20:32 +0000473 return true;
Steve Naroff7c9d72d2007-09-02 20:30:18 +0000474 if (Loc) *Loc = getLocStart();
475 return false;
476 }
Chris Lattner42e86b62007-11-01 02:45:17 +0000477 case DeclRefExprClass: {
478 const Decl *D = cast<DeclRefExpr>(this)->getDecl();
479 // Accept address of function.
480 if (isa<EnumConstantDecl>(D) || isa<FunctionDecl>(D))
Chris Lattner06db6132007-10-18 00:20:32 +0000481 return true;
Steve Naroff7c9d72d2007-09-02 20:30:18 +0000482 if (Loc) *Loc = getLocStart();
Chris Lattnerba3ddb22007-11-13 18:05:45 +0000483 if (isa<VarDecl>(D))
484 return TR->isArrayType();
Steve Naroff7c9d72d2007-09-02 20:30:18 +0000485 return false;
Chris Lattner42e86b62007-11-01 02:45:17 +0000486 }
Steve Narofff91f9722008-01-09 00:05:37 +0000487 case CompoundLiteralExprClass:
488 if (Loc) *Loc = getLocStart();
489 // Allow "(int []){2,4}", since the array will be converted to a pointer.
Nate Begemanc4e28e42008-01-25 05:34:48 +0000490 // Allow "(vector type){2,4}" since the elements are all constant.
491 return TR->isArrayType() || TR->isVectorType();
Steve Naroff7c9d72d2007-09-02 20:30:18 +0000492 case UnaryOperatorClass: {
493 const UnaryOperator *Exp = cast<UnaryOperator>(this);
494
Chris Lattnerba3ddb22007-11-13 18:05:45 +0000495 // C99 6.6p9
Chris Lattner35b662f2007-12-11 23:11:17 +0000496 if (Exp->getOpcode() == UnaryOperator::AddrOf) {
497 if (!Exp->getSubExpr()->hasStaticStorage()) {
498 if (Loc) *Loc = getLocStart();
499 return false;
500 }
501 return true;
502 }
Chris Lattnerba3ddb22007-11-13 18:05:45 +0000503
Steve Naroff7c9d72d2007-09-02 20:30:18 +0000504 // Get the operand value. If this is sizeof/alignof, do not evalute the
505 // operand. This affects C99 6.6p3.
Steve Narofff0b23542008-01-10 22:15:12 +0000506 if (!Exp->isSizeOfAlignOfOp() &&
507 Exp->getOpcode() != UnaryOperator::OffsetOf &&
Steve Naroff7c9d72d2007-09-02 20:30:18 +0000508 !Exp->getSubExpr()->isConstantExpr(Ctx, Loc))
509 return false;
510
511 switch (Exp->getOpcode()) {
512 // Address, indirect, pre/post inc/dec, etc are not valid constant exprs.
513 // See C99 6.6p3.
514 default:
515 if (Loc) *Loc = Exp->getOperatorLoc();
516 return false;
517 case UnaryOperator::Extension:
518 return true; // FIXME: this is wrong.
519 case UnaryOperator::SizeOf:
520 case UnaryOperator::AlignOf:
Steve Narofff0b23542008-01-10 22:15:12 +0000521 case UnaryOperator::OffsetOf:
Steve Naroff7c9d72d2007-09-02 20:30:18 +0000522 // sizeof(vla) is not a constantexpr: C99 6.5.3.4p2.
Chris Lattnerb3ff0822007-12-18 07:15:40 +0000523 if (!Exp->getSubExpr()->getType()->isConstantSizeType(Ctx)) {
524 if (Loc) *Loc = Exp->getOperatorLoc();
Steve Naroff7c9d72d2007-09-02 20:30:18 +0000525 return false;
Chris Lattnerb3ff0822007-12-18 07:15:40 +0000526 }
Chris Lattner06db6132007-10-18 00:20:32 +0000527 return true;
Steve Naroff7c9d72d2007-09-02 20:30:18 +0000528 case UnaryOperator::LNot:
529 case UnaryOperator::Plus:
530 case UnaryOperator::Minus:
531 case UnaryOperator::Not:
Chris Lattner06db6132007-10-18 00:20:32 +0000532 return true;
Steve Naroff7c9d72d2007-09-02 20:30:18 +0000533 }
Steve Naroff7c9d72d2007-09-02 20:30:18 +0000534 }
535 case SizeOfAlignOfTypeExprClass: {
536 const SizeOfAlignOfTypeExpr *Exp = cast<SizeOfAlignOfTypeExpr>(this);
537 // alignof always evaluates to a constant.
Chris Lattnerb3ff0822007-12-18 07:15:40 +0000538 if (Exp->isSizeOf() && !Exp->getArgumentType()->isConstantSizeType(Ctx)) {
539 if (Loc) *Loc = Exp->getOperatorLoc();
Steve Naroff7c9d72d2007-09-02 20:30:18 +0000540 return false;
Chris Lattnerb3ff0822007-12-18 07:15:40 +0000541 }
Chris Lattner06db6132007-10-18 00:20:32 +0000542 return true;
Steve Naroff7c9d72d2007-09-02 20:30:18 +0000543 }
544 case BinaryOperatorClass: {
545 const BinaryOperator *Exp = cast<BinaryOperator>(this);
546
547 // The LHS of a constant expr is always evaluated and needed.
548 if (!Exp->getLHS()->isConstantExpr(Ctx, Loc))
549 return false;
550
551 if (!Exp->getRHS()->isConstantExpr(Ctx, Loc))
552 return false;
Chris Lattner06db6132007-10-18 00:20:32 +0000553 return true;
Steve Naroff7c9d72d2007-09-02 20:30:18 +0000554 }
555 case ImplicitCastExprClass:
556 case CastExprClass: {
557 const Expr *SubExpr;
558 SourceLocation CastLoc;
559 if (const CastExpr *C = dyn_cast<CastExpr>(this)) {
560 SubExpr = C->getSubExpr();
561 CastLoc = C->getLParenLoc();
562 } else {
563 SubExpr = cast<ImplicitCastExpr>(this)->getSubExpr();
564 CastLoc = getLocStart();
565 }
566 if (!SubExpr->isConstantExpr(Ctx, Loc)) {
567 if (Loc) *Loc = SubExpr->getLocStart();
568 return false;
569 }
Chris Lattner06db6132007-10-18 00:20:32 +0000570 return true;
Steve Naroff7c9d72d2007-09-02 20:30:18 +0000571 }
572 case ConditionalOperatorClass: {
573 const ConditionalOperator *Exp = cast<ConditionalOperator>(this);
Chris Lattner06db6132007-10-18 00:20:32 +0000574 if (!Exp->getCond()->isConstantExpr(Ctx, Loc) ||
Anders Carlsson37365fc2007-11-30 19:04:31 +0000575 // Handle the GNU extension for missing LHS.
576 !(Exp->getLHS() && Exp->getLHS()->isConstantExpr(Ctx, Loc)) ||
Chris Lattner06db6132007-10-18 00:20:32 +0000577 !Exp->getRHS()->isConstantExpr(Ctx, Loc))
Steve Naroff7c9d72d2007-09-02 20:30:18 +0000578 return false;
Chris Lattner06db6132007-10-18 00:20:32 +0000579 return true;
Steve Naroff7c9d72d2007-09-02 20:30:18 +0000580 }
Steve Narofff0b23542008-01-10 22:15:12 +0000581 case InitListExprClass: {
582 const InitListExpr *Exp = cast<InitListExpr>(this);
583 unsigned numInits = Exp->getNumInits();
584 for (unsigned i = 0; i < numInits; i++) {
585 if (!Exp->getInit(i)->isConstantExpr(Ctx, Loc)) {
586 if (Loc) *Loc = Exp->getInit(i)->getLocStart();
587 return false;
588 }
589 }
590 return true;
Steve Naroff7c9d72d2007-09-02 20:30:18 +0000591 }
Steve Narofff0b23542008-01-10 22:15:12 +0000592 }
Steve Naroff7c9d72d2007-09-02 20:30:18 +0000593}
594
Chris Lattner4b009652007-07-25 00:24:17 +0000595/// isIntegerConstantExpr - this recursive routine will test if an expression is
596/// an integer constant expression. Note: With the introduction of VLA's in
597/// C99 the result of the sizeof operator is no longer always a constant
598/// expression. The generalization of the wording to include any subexpression
599/// that is not evaluated (C99 6.6p3) means that nonconstant subexpressions
600/// can appear as operands to other operators (e.g. &&, ||, ?:). For instance,
601/// "0 || f()" can be treated as a constant expression. In C90 this expression,
602/// occurring in a context requiring a constant, would have been a constraint
603/// violation. FIXME: This routine currently implements C90 semantics.
604/// To properly implement C99 semantics this routine will need to evaluate
605/// expressions involving operators previously mentioned.
606
607/// FIXME: Pass up a reason why! Invalid operation in i-c-e, division by zero,
608/// comma, etc
609///
610/// FIXME: This should ext-warn on overflow during evaluation! ISO C does not
Chris Lattner9d020b32007-09-26 00:47:26 +0000611/// permit this. This includes things like (int)1e1000
Chris Lattner4b009652007-07-25 00:24:17 +0000612///
613/// FIXME: Handle offsetof. Two things to do: Handle GCC's __builtin_offsetof
614/// to support gcc 4.0+ and handle the idiom GCC recognizes with a null pointer
615/// cast+dereference.
616bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
617 SourceLocation *Loc, bool isEvaluated) const {
618 switch (getStmtClass()) {
619 default:
620 if (Loc) *Loc = getLocStart();
621 return false;
622 case ParenExprClass:
623 return cast<ParenExpr>(this)->getSubExpr()->
624 isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated);
625 case IntegerLiteralClass:
626 Result = cast<IntegerLiteral>(this)->getValue();
627 break;
628 case CharacterLiteralClass: {
629 const CharacterLiteral *CL = cast<CharacterLiteral>(this);
Chris Lattner3496d522007-09-04 02:45:27 +0000630 Result.zextOrTrunc(
631 static_cast<uint32_t>(Ctx.getTypeSize(getType(), CL->getLoc())));
Chris Lattner4b009652007-07-25 00:24:17 +0000632 Result = CL->getValue();
633 Result.setIsUnsigned(!getType()->isSignedIntegerType());
634 break;
635 }
Steve Naroffc6f0fd32007-08-02 04:09:23 +0000636 case TypesCompatibleExprClass: {
637 const TypesCompatibleExpr *TCE = cast<TypesCompatibleExpr>(this);
Chris Lattner3496d522007-09-04 02:45:27 +0000638 Result.zextOrTrunc(
639 static_cast<uint32_t>(Ctx.getTypeSize(getType(), TCE->getLocStart())));
Steve Naroff85f0dc52007-10-15 20:41:53 +0000640 Result = Ctx.typesAreCompatible(TCE->getArgType1(), TCE->getArgType2());
Steve Naroff1200b5a2007-08-02 00:13:27 +0000641 break;
Steve Naroffc6f0fd32007-08-02 04:09:23 +0000642 }
Steve Naroff8d3b1702007-08-08 22:15:55 +0000643 case CallExprClass: {
644 const CallExpr *CE = cast<CallExpr>(this);
Chris Lattner3496d522007-09-04 02:45:27 +0000645 Result.zextOrTrunc(
646 static_cast<uint32_t>(Ctx.getTypeSize(getType(), CE->getLocStart())));
Steve Naroff8d3b1702007-08-08 22:15:55 +0000647 if (CE->isBuiltinClassifyType(Result))
648 break;
649 if (Loc) *Loc = getLocStart();
650 return false;
651 }
Chris Lattner4b009652007-07-25 00:24:17 +0000652 case DeclRefExprClass:
653 if (const EnumConstantDecl *D =
654 dyn_cast<EnumConstantDecl>(cast<DeclRefExpr>(this)->getDecl())) {
655 Result = D->getInitVal();
656 break;
657 }
658 if (Loc) *Loc = getLocStart();
659 return false;
660 case UnaryOperatorClass: {
661 const UnaryOperator *Exp = cast<UnaryOperator>(this);
662
663 // Get the operand value. If this is sizeof/alignof, do not evalute the
664 // operand. This affects C99 6.6p3.
Chris Lattner5a9b6242007-08-23 21:42:50 +0000665 if (!Exp->isSizeOfAlignOfOp() &&
666 !Exp->getSubExpr()->isIntegerConstantExpr(Result, Ctx, Loc,isEvaluated))
Chris Lattner4b009652007-07-25 00:24:17 +0000667 return false;
668
669 switch (Exp->getOpcode()) {
670 // Address, indirect, pre/post inc/dec, etc are not valid constant exprs.
671 // See C99 6.6p3.
672 default:
673 if (Loc) *Loc = Exp->getOperatorLoc();
674 return false;
675 case UnaryOperator::Extension:
676 return true; // FIXME: this is wrong.
677 case UnaryOperator::SizeOf:
678 case UnaryOperator::AlignOf:
679 // sizeof(vla) is not a constantexpr: C99 6.5.3.4p2.
Chris Lattnerb3ff0822007-12-18 07:15:40 +0000680 if (!Exp->getSubExpr()->getType()->isConstantSizeType(Ctx)) {
681 if (Loc) *Loc = Exp->getOperatorLoc();
Chris Lattner4b009652007-07-25 00:24:17 +0000682 return false;
Chris Lattnerb3ff0822007-12-18 07:15:40 +0000683 }
Chris Lattner4b009652007-07-25 00:24:17 +0000684
685 // Return the result in the right width.
Chris Lattner3496d522007-09-04 02:45:27 +0000686 Result.zextOrTrunc(
Chris Lattner9d020b32007-09-26 00:47:26 +0000687 static_cast<uint32_t>(Ctx.getTypeSize(getType(),
688 Exp->getOperatorLoc())));
Chris Lattner4b009652007-07-25 00:24:17 +0000689
690 // Get information about the size or align.
Chris Lattnerd4dc2672008-01-02 21:54:09 +0000691 if (Exp->getSubExpr()->getType()->isFunctionType()) {
692 // GCC extension: sizeof(function) = 1.
693 Result = Exp->getOpcode() == UnaryOperator::AlignOf ? 4 : 1;
694 } else if (Exp->getOpcode() == UnaryOperator::AlignOf) {
Chris Lattner4b009652007-07-25 00:24:17 +0000695 Result = Ctx.getTypeAlign(Exp->getSubExpr()->getType(),
696 Exp->getOperatorLoc());
Chris Lattnerd9ffbc92007-11-27 18:22:04 +0000697 } else {
Ted Kremenekd7f64cd2007-12-12 22:39:36 +0000698 unsigned CharSize =
699 Ctx.Target.getCharWidth(Ctx.getFullLoc(Exp->getOperatorLoc()));
700
Chris Lattnerd9ffbc92007-11-27 18:22:04 +0000701 Result = Ctx.getTypeSize(Exp->getSubExpr()->getType(),
702 Exp->getOperatorLoc()) / CharSize;
703 }
Chris Lattner4b009652007-07-25 00:24:17 +0000704 break;
705 case UnaryOperator::LNot: {
706 bool Val = Result != 0;
Chris Lattner3496d522007-09-04 02:45:27 +0000707 Result.zextOrTrunc(
Chris Lattner9d020b32007-09-26 00:47:26 +0000708 static_cast<uint32_t>(Ctx.getTypeSize(getType(),
709 Exp->getOperatorLoc())));
Chris Lattner4b009652007-07-25 00:24:17 +0000710 Result = Val;
711 break;
712 }
713 case UnaryOperator::Plus:
714 break;
715 case UnaryOperator::Minus:
716 Result = -Result;
717 break;
718 case UnaryOperator::Not:
719 Result = ~Result;
720 break;
721 }
722 break;
723 }
724 case SizeOfAlignOfTypeExprClass: {
725 const SizeOfAlignOfTypeExpr *Exp = cast<SizeOfAlignOfTypeExpr>(this);
726 // alignof always evaluates to a constant.
Chris Lattnerb3ff0822007-12-18 07:15:40 +0000727 if (Exp->isSizeOf() && !Exp->getArgumentType()->isConstantSizeType(Ctx)) {
728 if (Loc) *Loc = Exp->getOperatorLoc();
Chris Lattner4b009652007-07-25 00:24:17 +0000729 return false;
Chris Lattnerb3ff0822007-12-18 07:15:40 +0000730 }
Chris Lattner4b009652007-07-25 00:24:17 +0000731
732 // Return the result in the right width.
Chris Lattner3496d522007-09-04 02:45:27 +0000733 Result.zextOrTrunc(
734 static_cast<uint32_t>(Ctx.getTypeSize(getType(), Exp->getOperatorLoc())));
Chris Lattner4b009652007-07-25 00:24:17 +0000735
736 // Get information about the size or align.
Chris Lattnerd4dc2672008-01-02 21:54:09 +0000737 if (Exp->getArgumentType()->isFunctionType()) {
738 // GCC extension: sizeof(function) = 1.
739 Result = Exp->isSizeOf() ? 1 : 4;
740 } else if (Exp->isSizeOf()) {
Ted Kremeneka9d0fd92007-12-17 17:38:43 +0000741 unsigned CharSize =
742 Ctx.Target.getCharWidth(Ctx.getFullLoc(Exp->getOperatorLoc()));
743
744 Result = Ctx.getTypeSize(Exp->getArgumentType(),
745 Exp->getOperatorLoc()) / CharSize;
746 }
Chris Lattner4b009652007-07-25 00:24:17 +0000747 else
748 Result = Ctx.getTypeAlign(Exp->getArgumentType(), Exp->getOperatorLoc());
Ted Kremeneka9d0fd92007-12-17 17:38:43 +0000749
Chris Lattner4b009652007-07-25 00:24:17 +0000750 break;
751 }
752 case BinaryOperatorClass: {
753 const BinaryOperator *Exp = cast<BinaryOperator>(this);
754
755 // The LHS of a constant expr is always evaluated and needed.
756 if (!Exp->getLHS()->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated))
757 return false;
758
759 llvm::APSInt RHS(Result);
760
761 // The short-circuiting &&/|| operators don't necessarily evaluate their
762 // RHS. Make sure to pass isEvaluated down correctly.
763 if (Exp->isLogicalOp()) {
764 bool RHSEval;
765 if (Exp->getOpcode() == BinaryOperator::LAnd)
766 RHSEval = Result != 0;
767 else {
768 assert(Exp->getOpcode() == BinaryOperator::LOr &&"Unexpected logical");
769 RHSEval = Result == 0;
770 }
771
772 if (!Exp->getRHS()->isIntegerConstantExpr(RHS, Ctx, Loc,
773 isEvaluated & RHSEval))
774 return false;
775 } else {
776 if (!Exp->getRHS()->isIntegerConstantExpr(RHS, Ctx, Loc, isEvaluated))
777 return false;
778 }
779
780 switch (Exp->getOpcode()) {
781 default:
782 if (Loc) *Loc = getLocStart();
783 return false;
784 case BinaryOperator::Mul:
785 Result *= RHS;
786 break;
787 case BinaryOperator::Div:
788 if (RHS == 0) {
789 if (!isEvaluated) break;
790 if (Loc) *Loc = getLocStart();
791 return false;
792 }
793 Result /= RHS;
794 break;
795 case BinaryOperator::Rem:
796 if (RHS == 0) {
797 if (!isEvaluated) break;
798 if (Loc) *Loc = getLocStart();
799 return false;
800 }
801 Result %= RHS;
802 break;
803 case BinaryOperator::Add: Result += RHS; break;
804 case BinaryOperator::Sub: Result -= RHS; break;
805 case BinaryOperator::Shl:
Chris Lattner3496d522007-09-04 02:45:27 +0000806 Result <<=
807 static_cast<uint32_t>(RHS.getLimitedValue(Result.getBitWidth()-1));
Chris Lattner4b009652007-07-25 00:24:17 +0000808 break;
809 case BinaryOperator::Shr:
Chris Lattner3496d522007-09-04 02:45:27 +0000810 Result >>=
811 static_cast<uint32_t>(RHS.getLimitedValue(Result.getBitWidth()-1));
Chris Lattner4b009652007-07-25 00:24:17 +0000812 break;
813 case BinaryOperator::LT: Result = Result < RHS; break;
814 case BinaryOperator::GT: Result = Result > RHS; break;
815 case BinaryOperator::LE: Result = Result <= RHS; break;
816 case BinaryOperator::GE: Result = Result >= RHS; break;
817 case BinaryOperator::EQ: Result = Result == RHS; break;
818 case BinaryOperator::NE: Result = Result != RHS; break;
819 case BinaryOperator::And: Result &= RHS; break;
820 case BinaryOperator::Xor: Result ^= RHS; break;
821 case BinaryOperator::Or: Result |= RHS; break;
822 case BinaryOperator::LAnd:
823 Result = Result != 0 && RHS != 0;
824 break;
825 case BinaryOperator::LOr:
826 Result = Result != 0 || RHS != 0;
827 break;
828
829 case BinaryOperator::Comma:
830 // C99 6.6p3: "shall not contain assignment, ..., or comma operators,
831 // *except* when they are contained within a subexpression that is not
832 // evaluated". Note that Assignment can never happen due to constraints
833 // on the LHS subexpr, so we don't need to check it here.
834 if (isEvaluated) {
835 if (Loc) *Loc = getLocStart();
836 return false;
837 }
838
839 // The result of the constant expr is the RHS.
840 Result = RHS;
841 return true;
842 }
843
844 assert(!Exp->isAssignmentOp() && "LHS can't be a constant expr!");
845 break;
846 }
847 case ImplicitCastExprClass:
848 case CastExprClass: {
849 const Expr *SubExpr;
850 SourceLocation CastLoc;
851 if (const CastExpr *C = dyn_cast<CastExpr>(this)) {
852 SubExpr = C->getSubExpr();
853 CastLoc = C->getLParenLoc();
854 } else {
855 SubExpr = cast<ImplicitCastExpr>(this)->getSubExpr();
856 CastLoc = getLocStart();
857 }
858
859 // C99 6.6p6: shall only convert arithmetic types to integer types.
860 if (!SubExpr->getType()->isArithmeticType() ||
861 !getType()->isIntegerType()) {
862 if (Loc) *Loc = SubExpr->getLocStart();
863 return false;
864 }
Chris Lattner76a0c1b2007-09-22 19:04:13 +0000865
866 uint32_t DestWidth =
867 static_cast<uint32_t>(Ctx.getTypeSize(getType(), CastLoc));
868
Chris Lattner4b009652007-07-25 00:24:17 +0000869 // Handle simple integer->integer casts.
870 if (SubExpr->getType()->isIntegerType()) {
871 if (!SubExpr->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated))
872 return false;
873
874 // Figure out if this is a truncate, extend or noop cast.
Chris Lattner4b009652007-07-25 00:24:17 +0000875 // If the input is signed, do a sign extend, noop, or truncate.
Chris Lattner000c4102008-01-09 18:59:34 +0000876 if (getType()->isBooleanType()) {
877 // Conversion to bool compares against zero.
878 Result = Result != 0;
879 Result.zextOrTrunc(DestWidth);
880 } else if (SubExpr->getType()->isSignedIntegerType())
Chris Lattner4b009652007-07-25 00:24:17 +0000881 Result.sextOrTrunc(DestWidth);
882 else // If the input is unsigned, do a zero extend, noop, or truncate.
883 Result.zextOrTrunc(DestWidth);
884 break;
885 }
886
887 // Allow floating constants that are the immediate operands of casts or that
888 // are parenthesized.
889 const Expr *Operand = SubExpr;
890 while (const ParenExpr *PE = dyn_cast<ParenExpr>(Operand))
891 Operand = PE->getSubExpr();
Chris Lattner76a0c1b2007-09-22 19:04:13 +0000892
893 // If this isn't a floating literal, we can't handle it.
894 const FloatingLiteral *FL = dyn_cast<FloatingLiteral>(Operand);
895 if (!FL) {
896 if (Loc) *Loc = Operand->getLocStart();
897 return false;
Chris Lattner4b009652007-07-25 00:24:17 +0000898 }
Chris Lattner000c4102008-01-09 18:59:34 +0000899
900 // If the destination is boolean, compare against zero.
901 if (getType()->isBooleanType()) {
902 Result = !FL->getValue().isZero();
903 Result.zextOrTrunc(DestWidth);
904 break;
905 }
Chris Lattner76a0c1b2007-09-22 19:04:13 +0000906
907 // Determine whether we are converting to unsigned or signed.
908 bool DestSigned = getType()->isSignedIntegerType();
Chris Lattner9d020b32007-09-26 00:47:26 +0000909
910 // TODO: Warn on overflow, but probably not here: isIntegerConstantExpr can
911 // be called multiple times per AST.
Chris Lattner76a0c1b2007-09-22 19:04:13 +0000912 uint64_t Space[4];
Chris Lattner9d020b32007-09-26 00:47:26 +0000913 (void)FL->getValue().convertToInteger(Space, DestWidth, DestSigned,
914 llvm::APFloat::rmTowardZero);
Chris Lattner76a0c1b2007-09-22 19:04:13 +0000915 Result = llvm::APInt(DestWidth, 4, Space);
916 break;
Chris Lattner4b009652007-07-25 00:24:17 +0000917 }
918 case ConditionalOperatorClass: {
919 const ConditionalOperator *Exp = cast<ConditionalOperator>(this);
920
921 if (!Exp->getCond()->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated))
922 return false;
923
924 const Expr *TrueExp = Exp->getLHS();
925 const Expr *FalseExp = Exp->getRHS();
926 if (Result == 0) std::swap(TrueExp, FalseExp);
927
928 // Evaluate the false one first, discard the result.
Anders Carlsson37365fc2007-11-30 19:04:31 +0000929 if (FalseExp && !FalseExp->isIntegerConstantExpr(Result, Ctx, Loc, false))
Chris Lattner4b009652007-07-25 00:24:17 +0000930 return false;
931 // Evalute the true one, capture the result.
Anders Carlsson37365fc2007-11-30 19:04:31 +0000932 if (TrueExp &&
933 !TrueExp->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated))
Chris Lattner4b009652007-07-25 00:24:17 +0000934 return false;
935 break;
936 }
937 }
938
939 // Cases that are valid constant exprs fall through to here.
940 Result.setIsUnsigned(getType()->isUnsignedIntegerType());
941 return true;
942}
943
Chris Lattner4b009652007-07-25 00:24:17 +0000944/// isNullPointerConstant - C99 6.3.2.3p3 - Return true if this is either an
945/// integer constant expression with the value zero, or if this is one that is
946/// cast to void*.
947bool Expr::isNullPointerConstant(ASTContext &Ctx) const {
Steve Naroffa2e53222008-01-14 16:10:57 +0000948 // Strip off a cast to void*, if it exists.
949 if (const CastExpr *CE = dyn_cast<CastExpr>(this)) {
950 // Check that it is a cast to void*.
Chris Lattner4b009652007-07-25 00:24:17 +0000951 if (const PointerType *PT = dyn_cast<PointerType>(CE->getType())) {
952 QualType Pointee = PT->getPointeeType();
Steve Naroffa2e53222008-01-14 16:10:57 +0000953 if (Pointee.getQualifiers() == 0 && Pointee->isVoidType() && // to void*
954 CE->getSubExpr()->getType()->isIntegerType()) // from int.
955 return CE->getSubExpr()->isNullPointerConstant(Ctx);
Chris Lattner4b009652007-07-25 00:24:17 +0000956 }
Steve Naroffa2e53222008-01-14 16:10:57 +0000957 } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) {
958 // Ignore the ImplicitCastExpr type entirely.
959 return ICE->getSubExpr()->isNullPointerConstant(Ctx);
960 } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) {
961 // Accept ((void*)0) as a null pointer constant, as many other
962 // implementations do.
963 return PE->getSubExpr()->isNullPointerConstant(Ctx);
Steve Narofff33a9852008-01-14 02:53:34 +0000964 }
Steve Naroffa2e53222008-01-14 16:10:57 +0000965
966 // This expression must be an integer type.
967 if (!getType()->isIntegerType())
968 return false;
969
Chris Lattner4b009652007-07-25 00:24:17 +0000970 // If we have an integer constant expression, we need to *evaluate* it and
971 // test for the value 0.
972 llvm::APSInt Val(32);
Steve Naroffa2e53222008-01-14 16:10:57 +0000973 return isIntegerConstantExpr(Val, Ctx, 0, true) && Val == 0;
Chris Lattner4b009652007-07-25 00:24:17 +0000974}
Steve Naroffc11705f2007-07-28 23:10:27 +0000975
Chris Lattnera0d03a72007-08-03 17:31:20 +0000976unsigned OCUVectorElementExpr::getNumElements() const {
Chris Lattner50547852007-08-03 16:00:20 +0000977 return strlen(Accessor.getName());
978}
979
980
Chris Lattnerf4bf5512007-08-02 21:47:28 +0000981/// getComponentType - Determine whether the components of this access are
982/// "point" "color" or "texture" elements.
Chris Lattnera0d03a72007-08-03 17:31:20 +0000983OCUVectorElementExpr::ElementType
984OCUVectorElementExpr::getElementType() const {
Steve Naroffc11705f2007-07-28 23:10:27 +0000985 // derive the component type, no need to waste space.
986 const char *compStr = Accessor.getName();
Chris Lattnerabf25b32007-08-02 22:20:00 +0000987
Chris Lattner9096b792007-08-02 22:33:49 +0000988 if (OCUVectorType::getPointAccessorIdx(*compStr) != -1) return Point;
989 if (OCUVectorType::getColorAccessorIdx(*compStr) != -1) return Color;
Chris Lattnerabf25b32007-08-02 22:20:00 +0000990
Chris Lattner9096b792007-08-02 22:33:49 +0000991 assert(OCUVectorType::getTextureAccessorIdx(*compStr) != -1 &&
Chris Lattnerabf25b32007-08-02 22:20:00 +0000992 "getComponentType(): Illegal accessor");
993 return Texture;
Steve Naroffc11705f2007-07-28 23:10:27 +0000994}
Steve Naroffba67f692007-07-30 03:29:09 +0000995
Chris Lattnera0d03a72007-08-03 17:31:20 +0000996/// containsDuplicateElements - Return true if any element access is
Chris Lattnerf4bf5512007-08-02 21:47:28 +0000997/// repeated.
Chris Lattnera0d03a72007-08-03 17:31:20 +0000998bool OCUVectorElementExpr::containsDuplicateElements() const {
Steve Naroffba67f692007-07-30 03:29:09 +0000999 const char *compStr = Accessor.getName();
1000 unsigned length = strlen(compStr);
1001
1002 for (unsigned i = 0; i < length-1; i++) {
1003 const char *s = compStr+i;
1004 for (const char c = *s++; *s; s++)
1005 if (c == *s)
1006 return true;
1007 }
1008 return false;
1009}
Chris Lattner42158e72007-08-02 23:36:59 +00001010
1011/// getEncodedElementAccess - We encode fields with two bits per component.
Chris Lattnera0d03a72007-08-03 17:31:20 +00001012unsigned OCUVectorElementExpr::getEncodedElementAccess() const {
Chris Lattner42158e72007-08-02 23:36:59 +00001013 const char *compStr = Accessor.getName();
Chris Lattnera0d03a72007-08-03 17:31:20 +00001014 unsigned length = getNumElements();
Chris Lattner42158e72007-08-02 23:36:59 +00001015
1016 unsigned Result = 0;
1017
1018 while (length--) {
1019 Result <<= 2;
1020 int Idx = OCUVectorType::getAccessorIdx(compStr[length]);
1021 assert(Idx != -1 && "Invalid accessor letter");
1022 Result |= Idx;
1023 }
1024 return Result;
1025}
1026
Steve Naroff4ed9d662007-09-27 14:38:14 +00001027// constructor for instance messages.
Steve Naroff6cb1d362007-09-28 22:22:11 +00001028ObjCMessageExpr::ObjCMessageExpr(Expr *receiver, Selector selInfo,
Ted Kremenek42730c52008-01-07 19:49:32 +00001029 QualType retType, ObjCMethodDecl *mproto,
Steve Naroff1e1c3912007-11-03 16:37:59 +00001030 SourceLocation LBrac, SourceLocation RBrac,
Steve Naroff9f176d12007-11-15 13:05:42 +00001031 Expr **ArgExprs, unsigned nargs)
Steve Naroff1e1c3912007-11-03 16:37:59 +00001032 : Expr(ObjCMessageExprClass, retType), SelName(selInfo),
1033 MethodProto(mproto), ClassName(0) {
Steve Naroff9f176d12007-11-15 13:05:42 +00001034 NumArgs = nargs;
1035 SubExprs = new Expr*[NumArgs+1];
Steve Naroff4ed9d662007-09-27 14:38:14 +00001036 SubExprs[RECEIVER] = receiver;
Steve Naroff9f176d12007-11-15 13:05:42 +00001037 if (NumArgs) {
1038 for (unsigned i = 0; i != NumArgs; ++i)
Steve Naroff4ed9d662007-09-27 14:38:14 +00001039 SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]);
1040 }
Steve Naroffc39ca262007-09-18 23:55:05 +00001041 LBracloc = LBrac;
1042 RBracloc = RBrac;
1043}
1044
Steve Naroff4ed9d662007-09-27 14:38:14 +00001045// constructor for class messages.
1046// FIXME: clsName should be typed to ObjCInterfaceType
Steve Naroff6cb1d362007-09-28 22:22:11 +00001047ObjCMessageExpr::ObjCMessageExpr(IdentifierInfo *clsName, Selector selInfo,
Ted Kremenek42730c52008-01-07 19:49:32 +00001048 QualType retType, ObjCMethodDecl *mproto,
Steve Naroff1e1c3912007-11-03 16:37:59 +00001049 SourceLocation LBrac, SourceLocation RBrac,
Steve Naroff9f176d12007-11-15 13:05:42 +00001050 Expr **ArgExprs, unsigned nargs)
Steve Naroff1e1c3912007-11-03 16:37:59 +00001051 : Expr(ObjCMessageExprClass, retType), SelName(selInfo),
1052 MethodProto(mproto), ClassName(clsName) {
Steve Naroff9f176d12007-11-15 13:05:42 +00001053 NumArgs = nargs;
1054 SubExprs = new Expr*[NumArgs+1];
Steve Naroffc39ca262007-09-18 23:55:05 +00001055 SubExprs[RECEIVER] = 0;
Steve Naroff9f176d12007-11-15 13:05:42 +00001056 if (NumArgs) {
1057 for (unsigned i = 0; i != NumArgs; ++i)
Steve Naroff4ed9d662007-09-27 14:38:14 +00001058 SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]);
1059 }
Steve Naroffc39ca262007-09-18 23:55:05 +00001060 LBracloc = LBrac;
1061 RBracloc = RBrac;
1062}
1063
Chris Lattnerf624cd22007-10-25 00:29:32 +00001064
1065bool ChooseExpr::isConditionTrue(ASTContext &C) const {
1066 llvm::APSInt CondVal(32);
1067 bool IsConst = getCond()->isIntegerConstantExpr(CondVal, C);
1068 assert(IsConst && "Condition of choose expr must be i-c-e"); IsConst=IsConst;
1069 return CondVal != 0;
1070}
1071
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001072//===----------------------------------------------------------------------===//
1073// Child Iterators for iterating over subexpressions/substatements
1074//===----------------------------------------------------------------------===//
1075
1076// DeclRefExpr
Ted Kremeneka6478552007-10-18 23:28:49 +00001077Stmt::child_iterator DeclRefExpr::child_begin() { return child_iterator(); }
1078Stmt::child_iterator DeclRefExpr::child_end() { return child_iterator(); }
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001079
Steve Naroff5eb2a4a2007-11-12 14:29:37 +00001080// ObjCIvarRefExpr
1081Stmt::child_iterator ObjCIvarRefExpr::child_begin() { return child_iterator(); }
1082Stmt::child_iterator ObjCIvarRefExpr::child_end() { return child_iterator(); }
1083
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001084// PreDefinedExpr
Ted Kremeneka6478552007-10-18 23:28:49 +00001085Stmt::child_iterator PreDefinedExpr::child_begin() { return child_iterator(); }
1086Stmt::child_iterator PreDefinedExpr::child_end() { return child_iterator(); }
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001087
1088// IntegerLiteral
Ted Kremeneka6478552007-10-18 23:28:49 +00001089Stmt::child_iterator IntegerLiteral::child_begin() { return child_iterator(); }
1090Stmt::child_iterator IntegerLiteral::child_end() { return child_iterator(); }
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001091
1092// CharacterLiteral
Ted Kremeneka6478552007-10-18 23:28:49 +00001093Stmt::child_iterator CharacterLiteral::child_begin() { return child_iterator(); }
1094Stmt::child_iterator CharacterLiteral::child_end() { return child_iterator(); }
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001095
1096// FloatingLiteral
Ted Kremeneka6478552007-10-18 23:28:49 +00001097Stmt::child_iterator FloatingLiteral::child_begin() { return child_iterator(); }
1098Stmt::child_iterator FloatingLiteral::child_end() { return child_iterator(); }
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001099
Chris Lattner1de66eb2007-08-26 03:42:43 +00001100// ImaginaryLiteral
1101Stmt::child_iterator ImaginaryLiteral::child_begin() {
1102 return reinterpret_cast<Stmt**>(&Val);
1103}
1104Stmt::child_iterator ImaginaryLiteral::child_end() {
1105 return reinterpret_cast<Stmt**>(&Val)+1;
1106}
1107
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001108// StringLiteral
Ted Kremeneka6478552007-10-18 23:28:49 +00001109Stmt::child_iterator StringLiteral::child_begin() { return child_iterator(); }
1110Stmt::child_iterator StringLiteral::child_end() { return child_iterator(); }
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001111
1112// ParenExpr
1113Stmt::child_iterator ParenExpr::child_begin() {
1114 return reinterpret_cast<Stmt**>(&Val);
1115}
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001116Stmt::child_iterator ParenExpr::child_end() {
Chris Lattner1de66eb2007-08-26 03:42:43 +00001117 return reinterpret_cast<Stmt**>(&Val)+1;
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001118}
1119
1120// UnaryOperator
1121Stmt::child_iterator UnaryOperator::child_begin() {
Ted Kremenek6d7ea522007-12-15 00:39:18 +00001122 return reinterpret_cast<Stmt**>(&Val);
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001123}
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001124Stmt::child_iterator UnaryOperator::child_end() {
Ted Kremenek6d7ea522007-12-15 00:39:18 +00001125 return reinterpret_cast<Stmt**>(&Val+1);
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001126}
1127
1128// SizeOfAlignOfTypeExpr
Ted Kremeneka6478552007-10-18 23:28:49 +00001129Stmt::child_iterator SizeOfAlignOfTypeExpr::child_begin() {
Ted Kremenekb7cf0952007-12-14 22:52:23 +00001130 // If the type is a VLA type (and not a typedef), the size expression of the
1131 // VLA needs to be treated as an executable expression.
1132 if (VariableArrayType* T = dyn_cast<VariableArrayType>(Ty.getTypePtr()))
1133 return child_iterator(T);
1134 else
1135 return child_iterator();
Ted Kremeneka6478552007-10-18 23:28:49 +00001136}
1137Stmt::child_iterator SizeOfAlignOfTypeExpr::child_end() {
Ted Kremenekb7cf0952007-12-14 22:52:23 +00001138 return child_iterator();
Ted Kremeneka6478552007-10-18 23:28:49 +00001139}
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001140
1141// ArraySubscriptExpr
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001142Stmt::child_iterator ArraySubscriptExpr::child_begin() {
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001143 return reinterpret_cast<Stmt**>(&SubExprs);
1144}
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001145Stmt::child_iterator ArraySubscriptExpr::child_end() {
Chris Lattner1de66eb2007-08-26 03:42:43 +00001146 return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR;
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001147}
1148
1149// CallExpr
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001150Stmt::child_iterator CallExpr::child_begin() {
Ted Kremenek15ede502007-08-27 21:11:44 +00001151 return reinterpret_cast<Stmt**>(&SubExprs[0]);
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001152}
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001153Stmt::child_iterator CallExpr::child_end() {
Ted Kremenek15ede502007-08-27 21:11:44 +00001154 return reinterpret_cast<Stmt**>(&SubExprs[NumArgs+ARGS_START]);
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001155}
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001156
1157// MemberExpr
1158Stmt::child_iterator MemberExpr::child_begin() {
1159 return reinterpret_cast<Stmt**>(&Base);
1160}
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001161Stmt::child_iterator MemberExpr::child_end() {
Chris Lattner1de66eb2007-08-26 03:42:43 +00001162 return reinterpret_cast<Stmt**>(&Base)+1;
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001163}
1164
1165// OCUVectorElementExpr
1166Stmt::child_iterator OCUVectorElementExpr::child_begin() {
1167 return reinterpret_cast<Stmt**>(&Base);
1168}
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001169Stmt::child_iterator OCUVectorElementExpr::child_end() {
Chris Lattner1de66eb2007-08-26 03:42:43 +00001170 return reinterpret_cast<Stmt**>(&Base)+1;
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001171}
1172
1173// CompoundLiteralExpr
1174Stmt::child_iterator CompoundLiteralExpr::child_begin() {
1175 return reinterpret_cast<Stmt**>(&Init);
1176}
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001177Stmt::child_iterator CompoundLiteralExpr::child_end() {
Chris Lattner1de66eb2007-08-26 03:42:43 +00001178 return reinterpret_cast<Stmt**>(&Init)+1;
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001179}
1180
1181// ImplicitCastExpr
1182Stmt::child_iterator ImplicitCastExpr::child_begin() {
1183 return reinterpret_cast<Stmt**>(&Op);
1184}
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001185Stmt::child_iterator ImplicitCastExpr::child_end() {
Chris Lattner1de66eb2007-08-26 03:42:43 +00001186 return reinterpret_cast<Stmt**>(&Op)+1;
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001187}
1188
1189// CastExpr
1190Stmt::child_iterator CastExpr::child_begin() {
1191 return reinterpret_cast<Stmt**>(&Op);
1192}
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001193Stmt::child_iterator CastExpr::child_end() {
Chris Lattner1de66eb2007-08-26 03:42:43 +00001194 return reinterpret_cast<Stmt**>(&Op)+1;
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001195}
1196
1197// BinaryOperator
1198Stmt::child_iterator BinaryOperator::child_begin() {
1199 return reinterpret_cast<Stmt**>(&SubExprs);
1200}
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001201Stmt::child_iterator BinaryOperator::child_end() {
Chris Lattner1de66eb2007-08-26 03:42:43 +00001202 return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR;
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001203}
1204
1205// ConditionalOperator
1206Stmt::child_iterator ConditionalOperator::child_begin() {
1207 return reinterpret_cast<Stmt**>(&SubExprs);
1208}
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001209Stmt::child_iterator ConditionalOperator::child_end() {
Chris Lattner1de66eb2007-08-26 03:42:43 +00001210 return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR;
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001211}
1212
1213// AddrLabelExpr
Ted Kremeneka6478552007-10-18 23:28:49 +00001214Stmt::child_iterator AddrLabelExpr::child_begin() { return child_iterator(); }
1215Stmt::child_iterator AddrLabelExpr::child_end() { return child_iterator(); }
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001216
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001217// StmtExpr
1218Stmt::child_iterator StmtExpr::child_begin() {
1219 return reinterpret_cast<Stmt**>(&SubStmt);
1220}
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001221Stmt::child_iterator StmtExpr::child_end() {
Chris Lattner1de66eb2007-08-26 03:42:43 +00001222 return reinterpret_cast<Stmt**>(&SubStmt)+1;
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001223}
1224
1225// TypesCompatibleExpr
Ted Kremeneka6478552007-10-18 23:28:49 +00001226Stmt::child_iterator TypesCompatibleExpr::child_begin() {
1227 return child_iterator();
1228}
1229
1230Stmt::child_iterator TypesCompatibleExpr::child_end() {
1231 return child_iterator();
1232}
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001233
1234// ChooseExpr
1235Stmt::child_iterator ChooseExpr::child_begin() {
1236 return reinterpret_cast<Stmt**>(&SubExprs);
1237}
1238
1239Stmt::child_iterator ChooseExpr::child_end() {
Chris Lattner1de66eb2007-08-26 03:42:43 +00001240 return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR;
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001241}
1242
Nate Begeman9f3bfb72008-01-17 17:46:27 +00001243// OverloadExpr
1244Stmt::child_iterator OverloadExpr::child_begin() {
1245 return reinterpret_cast<Stmt**>(&SubExprs[0]);
1246}
1247Stmt::child_iterator OverloadExpr::child_end() {
1248 return reinterpret_cast<Stmt**>(&SubExprs[NumArgs]);
1249}
1250
Anders Carlsson36760332007-10-15 20:28:48 +00001251// VAArgExpr
1252Stmt::child_iterator VAArgExpr::child_begin() {
1253 return reinterpret_cast<Stmt**>(&Val);
1254}
1255
1256Stmt::child_iterator VAArgExpr::child_end() {
1257 return reinterpret_cast<Stmt**>(&Val)+1;
1258}
1259
Anders Carlsson762b7c72007-08-31 04:56:16 +00001260// InitListExpr
1261Stmt::child_iterator InitListExpr::child_begin() {
1262 return reinterpret_cast<Stmt**>(&InitExprs[0]);
1263}
1264Stmt::child_iterator InitListExpr::child_end() {
1265 return reinterpret_cast<Stmt**>(&InitExprs[NumInits]);
1266}
1267
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001268// ObjCStringLiteral
Ted Kremeneka6478552007-10-18 23:28:49 +00001269Stmt::child_iterator ObjCStringLiteral::child_begin() {
1270 return child_iterator();
1271}
1272Stmt::child_iterator ObjCStringLiteral::child_end() {
1273 return child_iterator();
1274}
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001275
1276// ObjCEncodeExpr
Ted Kremeneka6478552007-10-18 23:28:49 +00001277Stmt::child_iterator ObjCEncodeExpr::child_begin() { return child_iterator(); }
1278Stmt::child_iterator ObjCEncodeExpr::child_end() { return child_iterator(); }
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001279
Fariborz Jahanianf807c202007-10-16 20:40:23 +00001280// ObjCSelectorExpr
Ted Kremeneka6478552007-10-18 23:28:49 +00001281Stmt::child_iterator ObjCSelectorExpr::child_begin() {
1282 return child_iterator();
1283}
1284Stmt::child_iterator ObjCSelectorExpr::child_end() {
1285 return child_iterator();
1286}
Fariborz Jahanianf807c202007-10-16 20:40:23 +00001287
Fariborz Jahanianb391e6e2007-10-17 16:58:11 +00001288// ObjCProtocolExpr
Ted Kremeneka6478552007-10-18 23:28:49 +00001289Stmt::child_iterator ObjCProtocolExpr::child_begin() {
1290 return child_iterator();
1291}
1292Stmt::child_iterator ObjCProtocolExpr::child_end() {
1293 return child_iterator();
1294}
Fariborz Jahanianb391e6e2007-10-17 16:58:11 +00001295
Steve Naroffc39ca262007-09-18 23:55:05 +00001296// ObjCMessageExpr
1297Stmt::child_iterator ObjCMessageExpr::child_begin() {
1298 return reinterpret_cast<Stmt**>(&SubExprs[0]);
1299}
1300Stmt::child_iterator ObjCMessageExpr::child_end() {
Steve Naroff4ed9d662007-09-27 14:38:14 +00001301 return reinterpret_cast<Stmt**>(&SubExprs[getNumArgs()+ARGS_START]);
Steve Naroffc39ca262007-09-18 23:55:05 +00001302}
1303