blob: 986f0ad95f6bffd6135bde6a8911c25ceb99d76f [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- Expr.cpp - Expression AST Node Implementation --------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Expr class and subclasses.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/AST/Expr.h"
Chris Lattner2eadfb62007-07-15 23:32:58 +000015#include "clang/AST/ASTContext.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000016#include "clang/AST/StmtVisitor.h"
Chris Lattnerc7229c32007-10-07 08:58:51 +000017#include "clang/Basic/IdentifierTable.h"
Chris Lattnerda5a6b62007-11-27 18:22:04 +000018#include "clang/Basic/TargetInfo.h"
Reid Spencer5f016e22007-07-11 17:01:13 +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 Lattner73d0d4f2007-08-30 17:45:32 +000073 case OffsetOf: return "__builtin_offsetof";
Reid Spencer5f016e22007-07-11 17:01:13 +000074 }
75}
76
77//===----------------------------------------------------------------------===//
78// Postfix Operators.
79//===----------------------------------------------------------------------===//
80
81CallExpr::CallExpr(Expr *fn, Expr **args, unsigned numargs, QualType t,
82 SourceLocation rparenloc)
Ted Kremenek77ed8e42007-08-24 18:13:47 +000083 : Expr(CallExprClass, t), NumArgs(numargs) {
84 SubExprs = new Expr*[numargs+1];
85 SubExprs[FN] = fn;
Reid Spencer5f016e22007-07-11 17:01:13 +000086 for (unsigned i = 0; i != numargs; ++i)
Ted Kremenek77ed8e42007-08-24 18:13:47 +000087 SubExprs[i+ARGS_START] = args[i];
Reid Spencer5f016e22007-07-11 17:01:13 +000088 RParenLoc = rparenloc;
89}
90
Chris Lattnerd18b3292007-12-28 05:25:02 +000091/// setNumArgs - This changes the number of arguments present in this call.
92/// Any orphaned expressions are deleted by this, and any new operands are set
93/// to null.
94void CallExpr::setNumArgs(unsigned NumArgs) {
95 // No change, just return.
96 if (NumArgs == getNumArgs()) return;
97
98 // If shrinking # arguments, just delete the extras and forgot them.
99 if (NumArgs < getNumArgs()) {
100 for (unsigned i = NumArgs, e = getNumArgs(); i != e; ++i)
101 delete getArg(i);
102 this->NumArgs = NumArgs;
103 return;
104 }
105
106 // Otherwise, we are growing the # arguments. New an bigger argument array.
107 Expr **NewSubExprs = new Expr*[NumArgs+1];
108 // Copy over args.
109 for (unsigned i = 0; i != getNumArgs()+ARGS_START; ++i)
110 NewSubExprs[i] = SubExprs[i];
111 // Null out new args.
112 for (unsigned i = getNumArgs()+ARGS_START; i != NumArgs+ARGS_START; ++i)
113 NewSubExprs[i] = 0;
114
115 delete[] SubExprs;
116 SubExprs = NewSubExprs;
117 this->NumArgs = NumArgs;
118}
119
120
Steve Naroff13b7c5f2007-08-08 22:15:55 +0000121bool CallExpr::isBuiltinClassifyType(llvm::APSInt &Result) const {
122 // The following enum mimics gcc's internal "typeclass.h" file.
123 enum gcc_type_class {
124 no_type_class = -1,
125 void_type_class, integer_type_class, char_type_class,
126 enumeral_type_class, boolean_type_class,
127 pointer_type_class, reference_type_class, offset_type_class,
128 real_type_class, complex_type_class,
129 function_type_class, method_type_class,
130 record_type_class, union_type_class,
131 array_type_class, string_type_class,
132 lang_type_class
133 };
134 Result.setIsSigned(true);
135
136 // All simple function calls (e.g. func()) are implicitly cast to pointer to
137 // function. As a result, we try and obtain the DeclRefExpr from the
138 // ImplicitCastExpr.
139 const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee());
140 if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()).
141 return false;
142 const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr());
143 if (!DRE)
144 return false;
145
146 // We have a DeclRefExpr.
147 if (strcmp(DRE->getDecl()->getName(), "__builtin_classify_type") == 0) {
148 // If no argument was supplied, default to "no_type_class". This isn't
149 // ideal, however it's what gcc does.
150 Result = static_cast<uint64_t>(no_type_class);
151 if (NumArgs >= 1) {
152 QualType argType = getArg(0)->getType();
153
154 if (argType->isVoidType())
155 Result = void_type_class;
156 else if (argType->isEnumeralType())
157 Result = enumeral_type_class;
158 else if (argType->isBooleanType())
159 Result = boolean_type_class;
160 else if (argType->isCharType())
161 Result = string_type_class; // gcc doesn't appear to use char_type_class
162 else if (argType->isIntegerType())
163 Result = integer_type_class;
164 else if (argType->isPointerType())
165 Result = pointer_type_class;
166 else if (argType->isReferenceType())
167 Result = reference_type_class;
168 else if (argType->isRealType())
169 Result = real_type_class;
170 else if (argType->isComplexType())
171 Result = complex_type_class;
172 else if (argType->isFunctionType())
173 Result = function_type_class;
174 else if (argType->isStructureType())
175 Result = record_type_class;
176 else if (argType->isUnionType())
177 Result = union_type_class;
178 else if (argType->isArrayType())
179 Result = array_type_class;
180 else if (argType->isUnionType())
181 Result = union_type_class;
182 else // FIXME: offset_type_class, method_type_class, & lang_type_class?
Chris Lattner3ef5bc02007-11-08 17:56:40 +0000183 assert(0 && "CallExpr::isBuiltinClassifyType(): unimplemented type");
Steve Naroff13b7c5f2007-08-08 22:15:55 +0000184 }
185 return true;
186 }
187 return false;
188}
189
Reid Spencer5f016e22007-07-11 17:01:13 +0000190/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
191/// corresponds to, e.g. "<<=".
192const char *BinaryOperator::getOpcodeStr(Opcode Op) {
193 switch (Op) {
194 default: assert(0 && "Unknown binary operator");
195 case Mul: return "*";
196 case Div: return "/";
197 case Rem: return "%";
198 case Add: return "+";
199 case Sub: return "-";
200 case Shl: return "<<";
201 case Shr: return ">>";
202 case LT: return "<";
203 case GT: return ">";
204 case LE: return "<=";
205 case GE: return ">=";
206 case EQ: return "==";
207 case NE: return "!=";
208 case And: return "&";
209 case Xor: return "^";
210 case Or: return "|";
211 case LAnd: return "&&";
212 case LOr: return "||";
213 case Assign: return "=";
214 case MulAssign: return "*=";
215 case DivAssign: return "/=";
216 case RemAssign: return "%=";
217 case AddAssign: return "+=";
218 case SubAssign: return "-=";
219 case ShlAssign: return "<<=";
220 case ShrAssign: return ">>=";
221 case AndAssign: return "&=";
222 case XorAssign: return "^=";
223 case OrAssign: return "|=";
224 case Comma: return ",";
225 }
226}
227
Anders Carlsson66b5a8a2007-08-31 04:56:16 +0000228InitListExpr::InitListExpr(SourceLocation lbraceloc,
229 Expr **initexprs, unsigned numinits,
230 SourceLocation rbraceloc)
231 : Expr(InitListExprClass, QualType())
232 , NumInits(numinits)
233 , LBraceLoc(lbraceloc)
234 , RBraceLoc(rbraceloc)
235{
236 InitExprs = new Expr*[numinits];
237 for (unsigned i = 0; i != numinits; i++)
238 InitExprs[i] = initexprs[i];
239}
Reid Spencer5f016e22007-07-11 17:01:13 +0000240
241//===----------------------------------------------------------------------===//
242// Generic Expression Routines
243//===----------------------------------------------------------------------===//
244
245/// hasLocalSideEffect - Return true if this immediate expression has side
246/// effects, not counting any sub-expressions.
247bool Expr::hasLocalSideEffect() const {
248 switch (getStmtClass()) {
249 default:
250 return false;
251 case ParenExprClass:
252 return cast<ParenExpr>(this)->getSubExpr()->hasLocalSideEffect();
253 case UnaryOperatorClass: {
254 const UnaryOperator *UO = cast<UnaryOperator>(this);
255
256 switch (UO->getOpcode()) {
257 default: return false;
258 case UnaryOperator::PostInc:
259 case UnaryOperator::PostDec:
260 case UnaryOperator::PreInc:
261 case UnaryOperator::PreDec:
262 return true; // ++/--
263
264 case UnaryOperator::Deref:
265 // Dereferencing a volatile pointer is a side-effect.
266 return getType().isVolatileQualified();
267 case UnaryOperator::Real:
268 case UnaryOperator::Imag:
269 // accessing a piece of a volatile complex is a side-effect.
270 return UO->getSubExpr()->getType().isVolatileQualified();
271
272 case UnaryOperator::Extension:
273 return UO->getSubExpr()->hasLocalSideEffect();
274 }
275 }
Chris Lattnere7716e62007-12-01 06:07:34 +0000276 case BinaryOperatorClass: {
277 const BinaryOperator *BinOp = cast<BinaryOperator>(this);
278 // Consider comma to have side effects if the LHS and RHS both do.
279 if (BinOp->getOpcode() == BinaryOperator::Comma)
280 return BinOp->getLHS()->hasLocalSideEffect() &&
281 BinOp->getRHS()->hasLocalSideEffect();
282
283 return BinOp->isAssignmentOp();
284 }
Chris Lattnereb14fe82007-08-25 02:00:02 +0000285 case CompoundAssignOperatorClass:
Chris Lattner1f683e92007-08-25 01:55:00 +0000286 return true;
Reid Spencer5f016e22007-07-11 17:01:13 +0000287
Fariborz Jahanianab38e4b2007-12-01 19:58:28 +0000288 case ConditionalOperatorClass: {
289 const ConditionalOperator *Exp = cast<ConditionalOperator>(this);
290 return Exp->getCond()->hasLocalSideEffect()
291 || (Exp->getLHS() && Exp->getLHS()->hasLocalSideEffect())
292 || (Exp->getRHS() && Exp->getRHS()->hasLocalSideEffect());
293 }
294
Reid Spencer5f016e22007-07-11 17:01:13 +0000295 case MemberExprClass:
296 case ArraySubscriptExprClass:
297 // If the base pointer or element is to a volatile pointer/field, accessing
298 // if is a side effect.
299 return getType().isVolatileQualified();
300
301 case CallExprClass:
302 // TODO: check attributes for pure/const. "void foo() { strlen("bar"); }"
303 // should warn.
304 return true;
Chris Lattnera9c01022007-09-26 22:06:30 +0000305 case ObjCMessageExprClass:
306 return true;
Reid Spencer5f016e22007-07-11 17:01:13 +0000307
308 case CastExprClass:
309 // If this is a cast to void, check the operand. Otherwise, the result of
310 // the cast is unused.
311 if (getType()->isVoidType())
312 return cast<CastExpr>(this)->getSubExpr()->hasLocalSideEffect();
313 return false;
314 }
315}
316
317/// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or an
318/// incomplete type other than void. Nonarray expressions that can be lvalues:
319/// - name, where name must be a variable
320/// - e[i]
321/// - (e), where e must be an lvalue
322/// - e.name, where e must be an lvalue
323/// - e->name
324/// - *e, the type of e cannot be a function type
325/// - string-constant
Chris Lattner7da36f62007-10-30 22:53:42 +0000326/// - (__real__ e) and (__imag__ e) where e is an lvalue [GNU extension]
Bill Wendling08ad47c2007-07-17 03:52:31 +0000327/// - reference type [C++ [expr]]
Reid Spencer5f016e22007-07-11 17:01:13 +0000328///
Bill Wendlingca51c972007-07-16 07:07:56 +0000329Expr::isLvalueResult Expr::isLvalue() const {
Reid Spencer5f016e22007-07-11 17:01:13 +0000330 // first, check the type (C99 6.3.2.1)
Chris Lattnercb4f9a62007-07-21 05:33:26 +0000331 if (TR->isFunctionType()) // from isObjectType()
Reid Spencer5f016e22007-07-11 17:01:13 +0000332 return LV_NotObjectType;
333
Steve Naroff731ec572007-07-21 13:32:03 +0000334 if (TR->isVoidType())
Reid Spencer5f016e22007-07-11 17:01:13 +0000335 return LV_IncompleteVoidType;
Bill Wendling08ad47c2007-07-17 03:52:31 +0000336
Chris Lattnercb4f9a62007-07-21 05:33:26 +0000337 if (TR->isReferenceType()) // C++ [expr]
Bill Wendling08ad47c2007-07-17 03:52:31 +0000338 return LV_Valid;
339
Reid Spencer5f016e22007-07-11 17:01:13 +0000340 // the type looks fine, now check the expression
341 switch (getStmtClass()) {
342 case StringLiteralClass: // C99 6.5.1p4
Anders Carlsson7323a622007-11-30 22:47:59 +0000343 return LV_Valid;
Reid Spencer5f016e22007-07-11 17:01:13 +0000344 case ArraySubscriptExprClass: // C99 6.5.3p4 (e1[e2] == (*((e1)+(e2))))
345 // For vectors, make sure base is an lvalue (i.e. not a function call).
346 if (cast<ArraySubscriptExpr>(this)->getBase()->getType()->isVectorType())
347 return cast<ArraySubscriptExpr>(this)->getBase()->isLvalue();
348 return LV_Valid;
349 case DeclRefExprClass: // C99 6.5.1p2
350 if (isa<VarDecl>(cast<DeclRefExpr>(this)->getDecl()))
351 return LV_Valid;
352 break;
Anton Korobeynikovfdd75662007-07-12 15:26:50 +0000353 case MemberExprClass: { // C99 6.5.2.3p4
Reid Spencer5f016e22007-07-11 17:01:13 +0000354 const MemberExpr *m = cast<MemberExpr>(this);
355 return m->isArrow() ? LV_Valid : m->getBase()->isLvalue();
Anton Korobeynikovfdd75662007-07-12 15:26:50 +0000356 }
Chris Lattner7da36f62007-10-30 22:53:42 +0000357 case UnaryOperatorClass:
Reid Spencer5f016e22007-07-11 17:01:13 +0000358 if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Deref)
Chris Lattner7da36f62007-10-30 22:53:42 +0000359 return LV_Valid; // C99 6.5.3p4
360
361 if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Real ||
362 cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Imag)
363 return cast<UnaryOperator>(this)->getSubExpr()->isLvalue(); // GNU.
Reid Spencer5f016e22007-07-11 17:01:13 +0000364 break;
365 case ParenExprClass: // C99 6.5.1p5
366 return cast<ParenExpr>(this)->getSubExpr()->isLvalue();
Steve Naroffe6386392007-12-05 04:00:10 +0000367 case CompoundLiteralExprClass: // C99 6.5.2.5p5
368 return LV_Valid;
Chris Lattner6481a572007-08-03 17:31:20 +0000369 case OCUVectorElementExprClass:
370 if (cast<OCUVectorElementExpr>(this)->containsDuplicateElements())
Steve Narofffec0b492007-07-30 03:29:09 +0000371 return LV_DuplicateVectorComponents;
372 return LV_Valid;
Steve Naroff027282d2007-11-12 14:34:27 +0000373 case ObjCIvarRefExprClass: // ObjC instance variables are lvalues.
374 return LV_Valid;
Chris Lattnerfa28b302008-01-12 08:14:25 +0000375 case PreDefinedExprClass:
376 return LV_Valid;
Reid Spencer5f016e22007-07-11 17:01:13 +0000377 default:
378 break;
379 }
380 return LV_InvalidExpression;
381}
382
383/// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
384/// does not have an incomplete type, does not have a const-qualified type, and
385/// if it is a structure or union, does not have any member (including,
386/// recursively, any member or element of all contained aggregates or unions)
387/// with a const-qualified type.
Bill Wendlingca51c972007-07-16 07:07:56 +0000388Expr::isModifiableLvalueResult Expr::isModifiableLvalue() const {
Reid Spencer5f016e22007-07-11 17:01:13 +0000389 isLvalueResult lvalResult = isLvalue();
390
391 switch (lvalResult) {
392 case LV_Valid: break;
393 case LV_NotObjectType: return MLV_NotObjectType;
394 case LV_IncompleteVoidType: return MLV_IncompleteVoidType;
Steve Narofffec0b492007-07-30 03:29:09 +0000395 case LV_DuplicateVectorComponents: return MLV_DuplicateVectorComponents;
Reid Spencer5f016e22007-07-11 17:01:13 +0000396 case LV_InvalidExpression: return MLV_InvalidExpression;
397 }
398 if (TR.isConstQualified())
399 return MLV_ConstQualified;
400 if (TR->isArrayType())
401 return MLV_ArrayType;
402 if (TR->isIncompleteType())
403 return MLV_IncompleteType;
404
405 if (const RecordType *r = dyn_cast<RecordType>(TR.getCanonicalType())) {
406 if (r->hasConstFields())
407 return MLV_ConstQualified;
408 }
409 return MLV_Valid;
410}
411
Chris Lattner4cc62712007-11-27 21:35:27 +0000412/// hasStaticStorage - Return true if this expression has static storage
413/// duration. This means that the address of this expression is a link-time
414/// constant.
Chris Lattner1d09ecc2007-11-13 18:05:45 +0000415bool Expr::hasStaticStorage() const {
416 switch (getStmtClass()) {
417 default:
418 return false;
Chris Lattner4cc62712007-11-27 21:35:27 +0000419 case ParenExprClass:
420 return cast<ParenExpr>(this)->getSubExpr()->hasStaticStorage();
421 case ImplicitCastExprClass:
422 return cast<ImplicitCastExpr>(this)->getSubExpr()->hasStaticStorage();
Chris Lattner1d09ecc2007-11-13 18:05:45 +0000423 case DeclRefExprClass: {
424 const Decl *D = cast<DeclRefExpr>(this)->getDecl();
425 if (const VarDecl *VD = dyn_cast<VarDecl>(D))
426 return VD->hasStaticStorage();
427 return false;
428 }
Chris Lattnerfb708062007-11-28 04:30:09 +0000429 case MemberExprClass: {
Chris Lattner1d09ecc2007-11-13 18:05:45 +0000430 const MemberExpr *M = cast<MemberExpr>(this);
431 return !M->isArrow() && M->getBase()->hasStaticStorage();
Chris Lattnerfb708062007-11-28 04:30:09 +0000432 }
Chris Lattner4cc62712007-11-27 21:35:27 +0000433 case ArraySubscriptExprClass:
434 return cast<ArraySubscriptExpr>(this)->getBase()->hasStaticStorage();
Chris Lattnerfa28b302008-01-12 08:14:25 +0000435 case PreDefinedExprClass:
436 return true;
Chris Lattner1d09ecc2007-11-13 18:05:45 +0000437 }
438}
439
Steve Naroff38374b02007-09-02 20:30:18 +0000440bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const {
Steve Naroff38374b02007-09-02 20:30:18 +0000441 switch (getStmtClass()) {
442 default:
443 if (Loc) *Loc = getLocStart();
444 return false;
445 case ParenExprClass:
446 return cast<ParenExpr>(this)->getSubExpr()->isConstantExpr(Ctx, Loc);
447 case StringLiteralClass:
Steve Naroff5d37e322007-11-09 15:00:03 +0000448 case ObjCStringLiteralClass:
Steve Naroff38374b02007-09-02 20:30:18 +0000449 case FloatingLiteralClass:
450 case IntegerLiteralClass:
451 case CharacterLiteralClass:
452 case ImaginaryLiteralClass:
Anders Carlsson1a86b332007-10-17 00:52:43 +0000453 case TypesCompatibleExprClass:
454 case CXXBoolLiteralExprClass:
Chris Lattner2777e492007-10-18 00:20:32 +0000455 return true;
Steve Naroff38374b02007-09-02 20:30:18 +0000456 case CallExprClass: {
457 const CallExpr *CE = cast<CallExpr>(this);
458 llvm::APSInt Result(32);
Hartmut Kaiser86fd3552007-09-16 21:35:35 +0000459 Result.zextOrTrunc(
460 static_cast<uint32_t>(Ctx.getTypeSize(getType(), CE->getLocStart())));
Steve Naroff38374b02007-09-02 20:30:18 +0000461 if (CE->isBuiltinClassifyType(Result))
Chris Lattner2777e492007-10-18 00:20:32 +0000462 return true;
Steve Naroff38374b02007-09-02 20:30:18 +0000463 if (Loc) *Loc = getLocStart();
464 return false;
465 }
Chris Lattner4ef8dd62007-11-01 02:45:17 +0000466 case DeclRefExprClass: {
467 const Decl *D = cast<DeclRefExpr>(this)->getDecl();
468 // Accept address of function.
469 if (isa<EnumConstantDecl>(D) || isa<FunctionDecl>(D))
Chris Lattner2777e492007-10-18 00:20:32 +0000470 return true;
Steve Naroff38374b02007-09-02 20:30:18 +0000471 if (Loc) *Loc = getLocStart();
Chris Lattner1d09ecc2007-11-13 18:05:45 +0000472 if (isa<VarDecl>(D))
473 return TR->isArrayType();
Steve Naroff38374b02007-09-02 20:30:18 +0000474 return false;
Chris Lattner4ef8dd62007-11-01 02:45:17 +0000475 }
Steve Naroffb8f13a82008-01-09 00:05:37 +0000476 case CompoundLiteralExprClass:
477 if (Loc) *Loc = getLocStart();
478 // Allow "(int []){2,4}", since the array will be converted to a pointer.
479 return TR->isArrayType();
Steve Naroff38374b02007-09-02 20:30:18 +0000480 case UnaryOperatorClass: {
481 const UnaryOperator *Exp = cast<UnaryOperator>(this);
482
Chris Lattner1d09ecc2007-11-13 18:05:45 +0000483 // C99 6.6p9
Chris Lattner239c15e2007-12-11 23:11:17 +0000484 if (Exp->getOpcode() == UnaryOperator::AddrOf) {
485 if (!Exp->getSubExpr()->hasStaticStorage()) {
486 if (Loc) *Loc = getLocStart();
487 return false;
488 }
489 return true;
490 }
Chris Lattner1d09ecc2007-11-13 18:05:45 +0000491
Steve Naroff38374b02007-09-02 20:30:18 +0000492 // Get the operand value. If this is sizeof/alignof, do not evalute the
493 // operand. This affects C99 6.6p3.
Steve Naroffd0091aa2008-01-10 22:15:12 +0000494 if (!Exp->isSizeOfAlignOfOp() &&
495 Exp->getOpcode() != UnaryOperator::OffsetOf &&
Steve Naroff38374b02007-09-02 20:30:18 +0000496 !Exp->getSubExpr()->isConstantExpr(Ctx, Loc))
497 return false;
498
499 switch (Exp->getOpcode()) {
500 // Address, indirect, pre/post inc/dec, etc are not valid constant exprs.
501 // See C99 6.6p3.
502 default:
503 if (Loc) *Loc = Exp->getOperatorLoc();
504 return false;
505 case UnaryOperator::Extension:
506 return true; // FIXME: this is wrong.
507 case UnaryOperator::SizeOf:
508 case UnaryOperator::AlignOf:
Steve Naroffd0091aa2008-01-10 22:15:12 +0000509 case UnaryOperator::OffsetOf:
Steve Naroff38374b02007-09-02 20:30:18 +0000510 // sizeof(vla) is not a constantexpr: C99 6.5.3.4p2.
Chris Lattner65383472007-12-18 07:15:40 +0000511 if (!Exp->getSubExpr()->getType()->isConstantSizeType(Ctx)) {
512 if (Loc) *Loc = Exp->getOperatorLoc();
Steve Naroff38374b02007-09-02 20:30:18 +0000513 return false;
Chris Lattner65383472007-12-18 07:15:40 +0000514 }
Chris Lattner2777e492007-10-18 00:20:32 +0000515 return true;
Steve Naroff38374b02007-09-02 20:30:18 +0000516 case UnaryOperator::LNot:
517 case UnaryOperator::Plus:
518 case UnaryOperator::Minus:
519 case UnaryOperator::Not:
Chris Lattner2777e492007-10-18 00:20:32 +0000520 return true;
Steve Naroff38374b02007-09-02 20:30:18 +0000521 }
Steve Naroff38374b02007-09-02 20:30:18 +0000522 }
523 case SizeOfAlignOfTypeExprClass: {
524 const SizeOfAlignOfTypeExpr *Exp = cast<SizeOfAlignOfTypeExpr>(this);
525 // alignof always evaluates to a constant.
Chris Lattner65383472007-12-18 07:15:40 +0000526 if (Exp->isSizeOf() && !Exp->getArgumentType()->isConstantSizeType(Ctx)) {
527 if (Loc) *Loc = Exp->getOperatorLoc();
Steve Naroff38374b02007-09-02 20:30:18 +0000528 return false;
Chris Lattner65383472007-12-18 07:15:40 +0000529 }
Chris Lattner2777e492007-10-18 00:20:32 +0000530 return true;
Steve Naroff38374b02007-09-02 20:30:18 +0000531 }
532 case BinaryOperatorClass: {
533 const BinaryOperator *Exp = cast<BinaryOperator>(this);
534
535 // The LHS of a constant expr is always evaluated and needed.
536 if (!Exp->getLHS()->isConstantExpr(Ctx, Loc))
537 return false;
538
539 if (!Exp->getRHS()->isConstantExpr(Ctx, Loc))
540 return false;
Chris Lattner2777e492007-10-18 00:20:32 +0000541 return true;
Steve Naroff38374b02007-09-02 20:30:18 +0000542 }
543 case ImplicitCastExprClass:
544 case CastExprClass: {
545 const Expr *SubExpr;
546 SourceLocation CastLoc;
547 if (const CastExpr *C = dyn_cast<CastExpr>(this)) {
548 SubExpr = C->getSubExpr();
549 CastLoc = C->getLParenLoc();
550 } else {
551 SubExpr = cast<ImplicitCastExpr>(this)->getSubExpr();
552 CastLoc = getLocStart();
553 }
554 if (!SubExpr->isConstantExpr(Ctx, Loc)) {
555 if (Loc) *Loc = SubExpr->getLocStart();
556 return false;
557 }
Chris Lattner2777e492007-10-18 00:20:32 +0000558 return true;
Steve Naroff38374b02007-09-02 20:30:18 +0000559 }
560 case ConditionalOperatorClass: {
561 const ConditionalOperator *Exp = cast<ConditionalOperator>(this);
Chris Lattner2777e492007-10-18 00:20:32 +0000562 if (!Exp->getCond()->isConstantExpr(Ctx, Loc) ||
Anders Carlsson39073232007-11-30 19:04:31 +0000563 // Handle the GNU extension for missing LHS.
564 !(Exp->getLHS() && Exp->getLHS()->isConstantExpr(Ctx, Loc)) ||
Chris Lattner2777e492007-10-18 00:20:32 +0000565 !Exp->getRHS()->isConstantExpr(Ctx, Loc))
Steve Naroff38374b02007-09-02 20:30:18 +0000566 return false;
Chris Lattner2777e492007-10-18 00:20:32 +0000567 return true;
Steve Naroff38374b02007-09-02 20:30:18 +0000568 }
Steve Naroffd0091aa2008-01-10 22:15:12 +0000569 case InitListExprClass: {
570 const InitListExpr *Exp = cast<InitListExpr>(this);
571 unsigned numInits = Exp->getNumInits();
572 for (unsigned i = 0; i < numInits; i++) {
573 if (!Exp->getInit(i)->isConstantExpr(Ctx, Loc)) {
574 if (Loc) *Loc = Exp->getInit(i)->getLocStart();
575 return false;
576 }
577 }
578 return true;
Steve Naroff38374b02007-09-02 20:30:18 +0000579 }
Steve Naroffd0091aa2008-01-10 22:15:12 +0000580 }
Steve Naroff38374b02007-09-02 20:30:18 +0000581}
582
Reid Spencer5f016e22007-07-11 17:01:13 +0000583/// isIntegerConstantExpr - this recursive routine will test if an expression is
584/// an integer constant expression. Note: With the introduction of VLA's in
585/// C99 the result of the sizeof operator is no longer always a constant
586/// expression. The generalization of the wording to include any subexpression
587/// that is not evaluated (C99 6.6p3) means that nonconstant subexpressions
588/// can appear as operands to other operators (e.g. &&, ||, ?:). For instance,
589/// "0 || f()" can be treated as a constant expression. In C90 this expression,
590/// occurring in a context requiring a constant, would have been a constraint
591/// violation. FIXME: This routine currently implements C90 semantics.
592/// To properly implement C99 semantics this routine will need to evaluate
593/// expressions involving operators previously mentioned.
594
595/// FIXME: Pass up a reason why! Invalid operation in i-c-e, division by zero,
596/// comma, etc
597///
598/// FIXME: This should ext-warn on overflow during evaluation! ISO C does not
Chris Lattnerccc213f2007-09-26 00:47:26 +0000599/// permit this. This includes things like (int)1e1000
Chris Lattnerce0afc02007-07-18 05:21:20 +0000600///
601/// FIXME: Handle offsetof. Two things to do: Handle GCC's __builtin_offsetof
602/// to support gcc 4.0+ and handle the idiom GCC recognizes with a null pointer
603/// cast+dereference.
Chris Lattner590b6642007-07-15 23:26:56 +0000604bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
605 SourceLocation *Loc, bool isEvaluated) const {
Reid Spencer5f016e22007-07-11 17:01:13 +0000606 switch (getStmtClass()) {
607 default:
608 if (Loc) *Loc = getLocStart();
609 return false;
Reid Spencer5f016e22007-07-11 17:01:13 +0000610 case ParenExprClass:
611 return cast<ParenExpr>(this)->getSubExpr()->
Chris Lattner590b6642007-07-15 23:26:56 +0000612 isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated);
Reid Spencer5f016e22007-07-11 17:01:13 +0000613 case IntegerLiteralClass:
614 Result = cast<IntegerLiteral>(this)->getValue();
615 break;
Chris Lattner2eadfb62007-07-15 23:32:58 +0000616 case CharacterLiteralClass: {
617 const CharacterLiteral *CL = cast<CharacterLiteral>(this);
Chris Lattner701e5eb2007-09-04 02:45:27 +0000618 Result.zextOrTrunc(
619 static_cast<uint32_t>(Ctx.getTypeSize(getType(), CL->getLoc())));
Chris Lattner2eadfb62007-07-15 23:32:58 +0000620 Result = CL->getValue();
Chris Lattnerf0fbcb32007-07-16 21:04:56 +0000621 Result.setIsUnsigned(!getType()->isSignedIntegerType());
Reid Spencer5f016e22007-07-11 17:01:13 +0000622 break;
Chris Lattner2eadfb62007-07-15 23:32:58 +0000623 }
Steve Naroff7b658aa2007-08-02 04:09:23 +0000624 case TypesCompatibleExprClass: {
625 const TypesCompatibleExpr *TCE = cast<TypesCompatibleExpr>(this);
Chris Lattner701e5eb2007-09-04 02:45:27 +0000626 Result.zextOrTrunc(
627 static_cast<uint32_t>(Ctx.getTypeSize(getType(), TCE->getLocStart())));
Steve Naroffec0550f2007-10-15 20:41:53 +0000628 Result = Ctx.typesAreCompatible(TCE->getArgType1(), TCE->getArgType2());
Steve Naroff389cecc2007-08-02 00:13:27 +0000629 break;
Steve Naroff7b658aa2007-08-02 04:09:23 +0000630 }
Steve Naroff13b7c5f2007-08-08 22:15:55 +0000631 case CallExprClass: {
632 const CallExpr *CE = cast<CallExpr>(this);
Chris Lattner701e5eb2007-09-04 02:45:27 +0000633 Result.zextOrTrunc(
634 static_cast<uint32_t>(Ctx.getTypeSize(getType(), CE->getLocStart())));
Steve Naroff13b7c5f2007-08-08 22:15:55 +0000635 if (CE->isBuiltinClassifyType(Result))
636 break;
637 if (Loc) *Loc = getLocStart();
638 return false;
639 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000640 case DeclRefExprClass:
641 if (const EnumConstantDecl *D =
642 dyn_cast<EnumConstantDecl>(cast<DeclRefExpr>(this)->getDecl())) {
643 Result = D->getInitVal();
644 break;
645 }
646 if (Loc) *Loc = getLocStart();
647 return false;
648 case UnaryOperatorClass: {
649 const UnaryOperator *Exp = cast<UnaryOperator>(this);
650
651 // Get the operand value. If this is sizeof/alignof, do not evalute the
652 // operand. This affects C99 6.6p3.
Chris Lattner602dafd2007-08-23 21:42:50 +0000653 if (!Exp->isSizeOfAlignOfOp() &&
654 !Exp->getSubExpr()->isIntegerConstantExpr(Result, Ctx, Loc,isEvaluated))
Reid Spencer5f016e22007-07-11 17:01:13 +0000655 return false;
656
657 switch (Exp->getOpcode()) {
658 // Address, indirect, pre/post inc/dec, etc are not valid constant exprs.
659 // See C99 6.6p3.
660 default:
661 if (Loc) *Loc = Exp->getOperatorLoc();
662 return false;
663 case UnaryOperator::Extension:
Chris Lattner76e773a2007-07-18 18:38:36 +0000664 return true; // FIXME: this is wrong.
Reid Spencer5f016e22007-07-11 17:01:13 +0000665 case UnaryOperator::SizeOf:
666 case UnaryOperator::AlignOf:
667 // sizeof(vla) is not a constantexpr: C99 6.5.3.4p2.
Chris Lattner65383472007-12-18 07:15:40 +0000668 if (!Exp->getSubExpr()->getType()->isConstantSizeType(Ctx)) {
669 if (Loc) *Loc = Exp->getOperatorLoc();
Reid Spencer5f016e22007-07-11 17:01:13 +0000670 return false;
Chris Lattner65383472007-12-18 07:15:40 +0000671 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000672
Chris Lattner76e773a2007-07-18 18:38:36 +0000673 // Return the result in the right width.
Chris Lattner701e5eb2007-09-04 02:45:27 +0000674 Result.zextOrTrunc(
Chris Lattnerccc213f2007-09-26 00:47:26 +0000675 static_cast<uint32_t>(Ctx.getTypeSize(getType(),
676 Exp->getOperatorLoc())));
Chris Lattner76e773a2007-07-18 18:38:36 +0000677
678 // Get information about the size or align.
Chris Lattnerefdd1572008-01-02 21:54:09 +0000679 if (Exp->getSubExpr()->getType()->isFunctionType()) {
680 // GCC extension: sizeof(function) = 1.
681 Result = Exp->getOpcode() == UnaryOperator::AlignOf ? 4 : 1;
682 } else if (Exp->getOpcode() == UnaryOperator::AlignOf) {
Chris Lattner76e773a2007-07-18 18:38:36 +0000683 Result = Ctx.getTypeAlign(Exp->getSubExpr()->getType(),
684 Exp->getOperatorLoc());
Chris Lattnerda5a6b62007-11-27 18:22:04 +0000685 } else {
Ted Kremenek9c728dc2007-12-12 22:39:36 +0000686 unsigned CharSize =
687 Ctx.Target.getCharWidth(Ctx.getFullLoc(Exp->getOperatorLoc()));
688
Chris Lattnerda5a6b62007-11-27 18:22:04 +0000689 Result = Ctx.getTypeSize(Exp->getSubExpr()->getType(),
690 Exp->getOperatorLoc()) / CharSize;
691 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000692 break;
693 case UnaryOperator::LNot: {
694 bool Val = Result != 0;
Chris Lattner701e5eb2007-09-04 02:45:27 +0000695 Result.zextOrTrunc(
Chris Lattnerccc213f2007-09-26 00:47:26 +0000696 static_cast<uint32_t>(Ctx.getTypeSize(getType(),
697 Exp->getOperatorLoc())));
Reid Spencer5f016e22007-07-11 17:01:13 +0000698 Result = Val;
699 break;
700 }
701 case UnaryOperator::Plus:
Reid Spencer5f016e22007-07-11 17:01:13 +0000702 break;
703 case UnaryOperator::Minus:
Reid Spencer5f016e22007-07-11 17:01:13 +0000704 Result = -Result;
705 break;
706 case UnaryOperator::Not:
Reid Spencer5f016e22007-07-11 17:01:13 +0000707 Result = ~Result;
708 break;
709 }
710 break;
711 }
712 case SizeOfAlignOfTypeExprClass: {
713 const SizeOfAlignOfTypeExpr *Exp = cast<SizeOfAlignOfTypeExpr>(this);
714 // alignof always evaluates to a constant.
Chris Lattner65383472007-12-18 07:15:40 +0000715 if (Exp->isSizeOf() && !Exp->getArgumentType()->isConstantSizeType(Ctx)) {
716 if (Loc) *Loc = Exp->getOperatorLoc();
Reid Spencer5f016e22007-07-11 17:01:13 +0000717 return false;
Chris Lattner65383472007-12-18 07:15:40 +0000718 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000719
Chris Lattner76e773a2007-07-18 18:38:36 +0000720 // Return the result in the right width.
Chris Lattner701e5eb2007-09-04 02:45:27 +0000721 Result.zextOrTrunc(
722 static_cast<uint32_t>(Ctx.getTypeSize(getType(), Exp->getOperatorLoc())));
Chris Lattner76e773a2007-07-18 18:38:36 +0000723
724 // Get information about the size or align.
Chris Lattnerefdd1572008-01-02 21:54:09 +0000725 if (Exp->getArgumentType()->isFunctionType()) {
726 // GCC extension: sizeof(function) = 1.
727 Result = Exp->isSizeOf() ? 1 : 4;
728 } else if (Exp->isSizeOf()) {
Ted Kremenek060e4702007-12-17 17:38:43 +0000729 unsigned CharSize =
730 Ctx.Target.getCharWidth(Ctx.getFullLoc(Exp->getOperatorLoc()));
731
732 Result = Ctx.getTypeSize(Exp->getArgumentType(),
733 Exp->getOperatorLoc()) / CharSize;
734 }
Chris Lattner76e773a2007-07-18 18:38:36 +0000735 else
736 Result = Ctx.getTypeAlign(Exp->getArgumentType(), Exp->getOperatorLoc());
Ted Kremenek060e4702007-12-17 17:38:43 +0000737
Reid Spencer5f016e22007-07-11 17:01:13 +0000738 break;
739 }
740 case BinaryOperatorClass: {
741 const BinaryOperator *Exp = cast<BinaryOperator>(this);
742
743 // The LHS of a constant expr is always evaluated and needed.
Chris Lattner590b6642007-07-15 23:26:56 +0000744 if (!Exp->getLHS()->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated))
Reid Spencer5f016e22007-07-11 17:01:13 +0000745 return false;
746
747 llvm::APSInt RHS(Result);
748
749 // The short-circuiting &&/|| operators don't necessarily evaluate their
750 // RHS. Make sure to pass isEvaluated down correctly.
751 if (Exp->isLogicalOp()) {
752 bool RHSEval;
753 if (Exp->getOpcode() == BinaryOperator::LAnd)
754 RHSEval = Result != 0;
755 else {
756 assert(Exp->getOpcode() == BinaryOperator::LOr &&"Unexpected logical");
757 RHSEval = Result == 0;
758 }
759
Chris Lattner590b6642007-07-15 23:26:56 +0000760 if (!Exp->getRHS()->isIntegerConstantExpr(RHS, Ctx, Loc,
Reid Spencer5f016e22007-07-11 17:01:13 +0000761 isEvaluated & RHSEval))
762 return false;
763 } else {
Chris Lattner590b6642007-07-15 23:26:56 +0000764 if (!Exp->getRHS()->isIntegerConstantExpr(RHS, Ctx, Loc, isEvaluated))
Reid Spencer5f016e22007-07-11 17:01:13 +0000765 return false;
766 }
767
Reid Spencer5f016e22007-07-11 17:01:13 +0000768 switch (Exp->getOpcode()) {
769 default:
770 if (Loc) *Loc = getLocStart();
771 return false;
772 case BinaryOperator::Mul:
773 Result *= RHS;
774 break;
775 case BinaryOperator::Div:
776 if (RHS == 0) {
777 if (!isEvaluated) break;
778 if (Loc) *Loc = getLocStart();
779 return false;
780 }
781 Result /= RHS;
782 break;
783 case BinaryOperator::Rem:
784 if (RHS == 0) {
785 if (!isEvaluated) break;
786 if (Loc) *Loc = getLocStart();
787 return false;
788 }
789 Result %= RHS;
790 break;
791 case BinaryOperator::Add: Result += RHS; break;
792 case BinaryOperator::Sub: Result -= RHS; break;
793 case BinaryOperator::Shl:
Chris Lattner701e5eb2007-09-04 02:45:27 +0000794 Result <<=
795 static_cast<uint32_t>(RHS.getLimitedValue(Result.getBitWidth()-1));
Reid Spencer5f016e22007-07-11 17:01:13 +0000796 break;
797 case BinaryOperator::Shr:
Chris Lattner701e5eb2007-09-04 02:45:27 +0000798 Result >>=
799 static_cast<uint32_t>(RHS.getLimitedValue(Result.getBitWidth()-1));
Reid Spencer5f016e22007-07-11 17:01:13 +0000800 break;
801 case BinaryOperator::LT: Result = Result < RHS; break;
802 case BinaryOperator::GT: Result = Result > RHS; break;
803 case BinaryOperator::LE: Result = Result <= RHS; break;
804 case BinaryOperator::GE: Result = Result >= RHS; break;
805 case BinaryOperator::EQ: Result = Result == RHS; break;
806 case BinaryOperator::NE: Result = Result != RHS; break;
807 case BinaryOperator::And: Result &= RHS; break;
808 case BinaryOperator::Xor: Result ^= RHS; break;
809 case BinaryOperator::Or: Result |= RHS; break;
810 case BinaryOperator::LAnd:
811 Result = Result != 0 && RHS != 0;
812 break;
813 case BinaryOperator::LOr:
814 Result = Result != 0 || RHS != 0;
815 break;
816
817 case BinaryOperator::Comma:
818 // C99 6.6p3: "shall not contain assignment, ..., or comma operators,
819 // *except* when they are contained within a subexpression that is not
820 // evaluated". Note that Assignment can never happen due to constraints
821 // on the LHS subexpr, so we don't need to check it here.
822 if (isEvaluated) {
823 if (Loc) *Loc = getLocStart();
824 return false;
825 }
826
827 // The result of the constant expr is the RHS.
828 Result = RHS;
829 return true;
830 }
831
832 assert(!Exp->isAssignmentOp() && "LHS can't be a constant expr!");
833 break;
834 }
Chris Lattner26dc7b32007-07-15 23:54:50 +0000835 case ImplicitCastExprClass:
Reid Spencer5f016e22007-07-11 17:01:13 +0000836 case CastExprClass: {
Chris Lattner26dc7b32007-07-15 23:54:50 +0000837 const Expr *SubExpr;
838 SourceLocation CastLoc;
839 if (const CastExpr *C = dyn_cast<CastExpr>(this)) {
840 SubExpr = C->getSubExpr();
841 CastLoc = C->getLParenLoc();
842 } else {
843 SubExpr = cast<ImplicitCastExpr>(this)->getSubExpr();
844 CastLoc = getLocStart();
845 }
846
Reid Spencer5f016e22007-07-11 17:01:13 +0000847 // C99 6.6p6: shall only convert arithmetic types to integer types.
Chris Lattner26dc7b32007-07-15 23:54:50 +0000848 if (!SubExpr->getType()->isArithmeticType() ||
849 !getType()->isIntegerType()) {
850 if (Loc) *Loc = SubExpr->getLocStart();
Reid Spencer5f016e22007-07-11 17:01:13 +0000851 return false;
852 }
Chris Lattner987b15d2007-09-22 19:04:13 +0000853
854 uint32_t DestWidth =
855 static_cast<uint32_t>(Ctx.getTypeSize(getType(), CastLoc));
856
Reid Spencer5f016e22007-07-11 17:01:13 +0000857 // Handle simple integer->integer casts.
Chris Lattner26dc7b32007-07-15 23:54:50 +0000858 if (SubExpr->getType()->isIntegerType()) {
859 if (!SubExpr->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated))
Reid Spencer5f016e22007-07-11 17:01:13 +0000860 return false;
Chris Lattner26dc7b32007-07-15 23:54:50 +0000861
862 // Figure out if this is a truncate, extend or noop cast.
Chris Lattner26dc7b32007-07-15 23:54:50 +0000863 // If the input is signed, do a sign extend, noop, or truncate.
Chris Lattnerc0a356b2008-01-09 18:59:34 +0000864 if (getType()->isBooleanType()) {
865 // Conversion to bool compares against zero.
866 Result = Result != 0;
867 Result.zextOrTrunc(DestWidth);
868 } else if (SubExpr->getType()->isSignedIntegerType())
Chris Lattner26dc7b32007-07-15 23:54:50 +0000869 Result.sextOrTrunc(DestWidth);
870 else // If the input is unsigned, do a zero extend, noop, or truncate.
871 Result.zextOrTrunc(DestWidth);
Reid Spencer5f016e22007-07-11 17:01:13 +0000872 break;
873 }
874
875 // Allow floating constants that are the immediate operands of casts or that
876 // are parenthesized.
Chris Lattner26dc7b32007-07-15 23:54:50 +0000877 const Expr *Operand = SubExpr;
Reid Spencer5f016e22007-07-11 17:01:13 +0000878 while (const ParenExpr *PE = dyn_cast<ParenExpr>(Operand))
879 Operand = PE->getSubExpr();
Chris Lattner987b15d2007-09-22 19:04:13 +0000880
881 // If this isn't a floating literal, we can't handle it.
882 const FloatingLiteral *FL = dyn_cast<FloatingLiteral>(Operand);
883 if (!FL) {
884 if (Loc) *Loc = Operand->getLocStart();
885 return false;
Reid Spencer5f016e22007-07-11 17:01:13 +0000886 }
Chris Lattnerc0a356b2008-01-09 18:59:34 +0000887
888 // If the destination is boolean, compare against zero.
889 if (getType()->isBooleanType()) {
890 Result = !FL->getValue().isZero();
891 Result.zextOrTrunc(DestWidth);
892 break;
893 }
Chris Lattner987b15d2007-09-22 19:04:13 +0000894
895 // Determine whether we are converting to unsigned or signed.
896 bool DestSigned = getType()->isSignedIntegerType();
Chris Lattnerccc213f2007-09-26 00:47:26 +0000897
898 // TODO: Warn on overflow, but probably not here: isIntegerConstantExpr can
899 // be called multiple times per AST.
Chris Lattner987b15d2007-09-22 19:04:13 +0000900 uint64_t Space[4];
Chris Lattnerccc213f2007-09-26 00:47:26 +0000901 (void)FL->getValue().convertToInteger(Space, DestWidth, DestSigned,
902 llvm::APFloat::rmTowardZero);
Chris Lattner987b15d2007-09-22 19:04:13 +0000903 Result = llvm::APInt(DestWidth, 4, Space);
904 break;
Reid Spencer5f016e22007-07-11 17:01:13 +0000905 }
906 case ConditionalOperatorClass: {
907 const ConditionalOperator *Exp = cast<ConditionalOperator>(this);
908
Chris Lattner590b6642007-07-15 23:26:56 +0000909 if (!Exp->getCond()->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated))
Reid Spencer5f016e22007-07-11 17:01:13 +0000910 return false;
911
912 const Expr *TrueExp = Exp->getLHS();
913 const Expr *FalseExp = Exp->getRHS();
914 if (Result == 0) std::swap(TrueExp, FalseExp);
915
916 // Evaluate the false one first, discard the result.
Anders Carlsson39073232007-11-30 19:04:31 +0000917 if (FalseExp && !FalseExp->isIntegerConstantExpr(Result, Ctx, Loc, false))
Reid Spencer5f016e22007-07-11 17:01:13 +0000918 return false;
919 // Evalute the true one, capture the result.
Anders Carlsson39073232007-11-30 19:04:31 +0000920 if (TrueExp &&
921 !TrueExp->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated))
Reid Spencer5f016e22007-07-11 17:01:13 +0000922 return false;
Reid Spencer5f016e22007-07-11 17:01:13 +0000923 break;
924 }
925 }
926
927 // Cases that are valid constant exprs fall through to here.
928 Result.setIsUnsigned(getType()->isUnsignedIntegerType());
929 return true;
930}
931
Reid Spencer5f016e22007-07-11 17:01:13 +0000932/// isNullPointerConstant - C99 6.3.2.3p3 - Return true if this is either an
933/// integer constant expression with the value zero, or if this is one that is
934/// cast to void*.
Chris Lattner590b6642007-07-15 23:26:56 +0000935bool Expr::isNullPointerConstant(ASTContext &Ctx) const {
Steve Naroffaa58f002008-01-14 16:10:57 +0000936 // Strip off a cast to void*, if it exists.
937 if (const CastExpr *CE = dyn_cast<CastExpr>(this)) {
938 // Check that it is a cast to void*.
Reid Spencer5f016e22007-07-11 17:01:13 +0000939 if (const PointerType *PT = dyn_cast<PointerType>(CE->getType())) {
940 QualType Pointee = PT->getPointeeType();
Steve Naroffaa58f002008-01-14 16:10:57 +0000941 if (Pointee.getQualifiers() == 0 && Pointee->isVoidType() && // to void*
942 CE->getSubExpr()->getType()->isIntegerType()) // from int.
943 return CE->getSubExpr()->isNullPointerConstant(Ctx);
Reid Spencer5f016e22007-07-11 17:01:13 +0000944 }
Steve Naroffaa58f002008-01-14 16:10:57 +0000945 } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) {
946 // Ignore the ImplicitCastExpr type entirely.
947 return ICE->getSubExpr()->isNullPointerConstant(Ctx);
948 } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) {
949 // Accept ((void*)0) as a null pointer constant, as many other
950 // implementations do.
951 return PE->getSubExpr()->isNullPointerConstant(Ctx);
Steve Naroffaaffbf72008-01-14 02:53:34 +0000952 }
Steve Naroffaa58f002008-01-14 16:10:57 +0000953
954 // This expression must be an integer type.
955 if (!getType()->isIntegerType())
956 return false;
957
Reid Spencer5f016e22007-07-11 17:01:13 +0000958 // If we have an integer constant expression, we need to *evaluate* it and
959 // test for the value 0.
960 llvm::APSInt Val(32);
Steve Naroffaa58f002008-01-14 16:10:57 +0000961 return isIntegerConstantExpr(Val, Ctx, 0, true) && Val == 0;
Reid Spencer5f016e22007-07-11 17:01:13 +0000962}
Steve Naroff31a45842007-07-28 23:10:27 +0000963
Chris Lattner6481a572007-08-03 17:31:20 +0000964unsigned OCUVectorElementExpr::getNumElements() const {
Chris Lattner4d0ac882007-08-03 16:00:20 +0000965 return strlen(Accessor.getName());
966}
967
968
Chris Lattnercb92a112007-08-02 21:47:28 +0000969/// getComponentType - Determine whether the components of this access are
970/// "point" "color" or "texture" elements.
Chris Lattner6481a572007-08-03 17:31:20 +0000971OCUVectorElementExpr::ElementType
972OCUVectorElementExpr::getElementType() const {
Steve Naroff31a45842007-07-28 23:10:27 +0000973 // derive the component type, no need to waste space.
974 const char *compStr = Accessor.getName();
Chris Lattnerb4878f42007-08-02 22:20:00 +0000975
Chris Lattner88dca042007-08-02 22:33:49 +0000976 if (OCUVectorType::getPointAccessorIdx(*compStr) != -1) return Point;
977 if (OCUVectorType::getColorAccessorIdx(*compStr) != -1) return Color;
Chris Lattnerb4878f42007-08-02 22:20:00 +0000978
Chris Lattner88dca042007-08-02 22:33:49 +0000979 assert(OCUVectorType::getTextureAccessorIdx(*compStr) != -1 &&
Chris Lattnerb4878f42007-08-02 22:20:00 +0000980 "getComponentType(): Illegal accessor");
981 return Texture;
Steve Naroff31a45842007-07-28 23:10:27 +0000982}
Steve Narofffec0b492007-07-30 03:29:09 +0000983
Chris Lattner6481a572007-08-03 17:31:20 +0000984/// containsDuplicateElements - Return true if any element access is
Chris Lattnercb92a112007-08-02 21:47:28 +0000985/// repeated.
Chris Lattner6481a572007-08-03 17:31:20 +0000986bool OCUVectorElementExpr::containsDuplicateElements() const {
Steve Narofffec0b492007-07-30 03:29:09 +0000987 const char *compStr = Accessor.getName();
988 unsigned length = strlen(compStr);
989
990 for (unsigned i = 0; i < length-1; i++) {
991 const char *s = compStr+i;
992 for (const char c = *s++; *s; s++)
993 if (c == *s)
994 return true;
995 }
996 return false;
997}
Chris Lattnerb8f849d2007-08-02 23:36:59 +0000998
999/// getEncodedElementAccess - We encode fields with two bits per component.
Chris Lattner6481a572007-08-03 17:31:20 +00001000unsigned OCUVectorElementExpr::getEncodedElementAccess() const {
Chris Lattnerb8f849d2007-08-02 23:36:59 +00001001 const char *compStr = Accessor.getName();
Chris Lattner6481a572007-08-03 17:31:20 +00001002 unsigned length = getNumElements();
Chris Lattnerb8f849d2007-08-02 23:36:59 +00001003
1004 unsigned Result = 0;
1005
1006 while (length--) {
1007 Result <<= 2;
1008 int Idx = OCUVectorType::getAccessorIdx(compStr[length]);
1009 assert(Idx != -1 && "Invalid accessor letter");
1010 Result |= Idx;
1011 }
1012 return Result;
1013}
1014
Steve Naroff68d331a2007-09-27 14:38:14 +00001015// constructor for instance messages.
Steve Naroffbcfb06a2007-09-28 22:22:11 +00001016ObjCMessageExpr::ObjCMessageExpr(Expr *receiver, Selector selInfo,
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001017 QualType retType, ObjCMethodDecl *mproto,
Steve Naroffdb611d52007-11-03 16:37:59 +00001018 SourceLocation LBrac, SourceLocation RBrac,
Steve Naroff49f109c2007-11-15 13:05:42 +00001019 Expr **ArgExprs, unsigned nargs)
Steve Naroffdb611d52007-11-03 16:37:59 +00001020 : Expr(ObjCMessageExprClass, retType), SelName(selInfo),
1021 MethodProto(mproto), ClassName(0) {
Steve Naroff49f109c2007-11-15 13:05:42 +00001022 NumArgs = nargs;
1023 SubExprs = new Expr*[NumArgs+1];
Steve Naroff68d331a2007-09-27 14:38:14 +00001024 SubExprs[RECEIVER] = receiver;
Steve Naroff49f109c2007-11-15 13:05:42 +00001025 if (NumArgs) {
1026 for (unsigned i = 0; i != NumArgs; ++i)
Steve Naroff68d331a2007-09-27 14:38:14 +00001027 SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]);
1028 }
Steve Naroff563477d2007-09-18 23:55:05 +00001029 LBracloc = LBrac;
1030 RBracloc = RBrac;
1031}
1032
Steve Naroff68d331a2007-09-27 14:38:14 +00001033// constructor for class messages.
1034// FIXME: clsName should be typed to ObjCInterfaceType
Steve Naroffbcfb06a2007-09-28 22:22:11 +00001035ObjCMessageExpr::ObjCMessageExpr(IdentifierInfo *clsName, Selector selInfo,
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001036 QualType retType, ObjCMethodDecl *mproto,
Steve Naroffdb611d52007-11-03 16:37:59 +00001037 SourceLocation LBrac, SourceLocation RBrac,
Steve Naroff49f109c2007-11-15 13:05:42 +00001038 Expr **ArgExprs, unsigned nargs)
Steve Naroffdb611d52007-11-03 16:37:59 +00001039 : Expr(ObjCMessageExprClass, retType), SelName(selInfo),
1040 MethodProto(mproto), ClassName(clsName) {
Steve Naroff49f109c2007-11-15 13:05:42 +00001041 NumArgs = nargs;
1042 SubExprs = new Expr*[NumArgs+1];
Steve Naroff563477d2007-09-18 23:55:05 +00001043 SubExprs[RECEIVER] = 0;
Steve Naroff49f109c2007-11-15 13:05:42 +00001044 if (NumArgs) {
1045 for (unsigned i = 0; i != NumArgs; ++i)
Steve Naroff68d331a2007-09-27 14:38:14 +00001046 SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]);
1047 }
Steve Naroff563477d2007-09-18 23:55:05 +00001048 LBracloc = LBrac;
1049 RBracloc = RBrac;
1050}
1051
Chris Lattner27437ca2007-10-25 00:29:32 +00001052
1053bool ChooseExpr::isConditionTrue(ASTContext &C) const {
1054 llvm::APSInt CondVal(32);
1055 bool IsConst = getCond()->isIntegerConstantExpr(CondVal, C);
1056 assert(IsConst && "Condition of choose expr must be i-c-e"); IsConst=IsConst;
1057 return CondVal != 0;
1058}
1059
Ted Kremenek77ed8e42007-08-24 18:13:47 +00001060//===----------------------------------------------------------------------===//
1061// Child Iterators for iterating over subexpressions/substatements
1062//===----------------------------------------------------------------------===//
1063
1064// DeclRefExpr
Ted Kremenek9ac59282007-10-18 23:28:49 +00001065Stmt::child_iterator DeclRefExpr::child_begin() { return child_iterator(); }
1066Stmt::child_iterator DeclRefExpr::child_end() { return child_iterator(); }
Ted Kremenek77ed8e42007-08-24 18:13:47 +00001067
Steve Naroff7779db42007-11-12 14:29:37 +00001068// ObjCIvarRefExpr
1069Stmt::child_iterator ObjCIvarRefExpr::child_begin() { return child_iterator(); }
1070Stmt::child_iterator ObjCIvarRefExpr::child_end() { return child_iterator(); }
1071
Ted Kremenek77ed8e42007-08-24 18:13:47 +00001072// PreDefinedExpr
Ted Kremenek9ac59282007-10-18 23:28:49 +00001073Stmt::child_iterator PreDefinedExpr::child_begin() { return child_iterator(); }
1074Stmt::child_iterator PreDefinedExpr::child_end() { return child_iterator(); }
Ted Kremenek77ed8e42007-08-24 18:13:47 +00001075
1076// IntegerLiteral
Ted Kremenek9ac59282007-10-18 23:28:49 +00001077Stmt::child_iterator IntegerLiteral::child_begin() { return child_iterator(); }
1078Stmt::child_iterator IntegerLiteral::child_end() { return child_iterator(); }
Ted Kremenek77ed8e42007-08-24 18:13:47 +00001079
1080// CharacterLiteral
Ted Kremenek9ac59282007-10-18 23:28:49 +00001081Stmt::child_iterator CharacterLiteral::child_begin() { return child_iterator(); }
1082Stmt::child_iterator CharacterLiteral::child_end() { return child_iterator(); }
Ted Kremenek77ed8e42007-08-24 18:13:47 +00001083
1084// FloatingLiteral
Ted Kremenek9ac59282007-10-18 23:28:49 +00001085Stmt::child_iterator FloatingLiteral::child_begin() { return child_iterator(); }
1086Stmt::child_iterator FloatingLiteral::child_end() { return child_iterator(); }
Ted Kremenek77ed8e42007-08-24 18:13:47 +00001087
Chris Lattner5d661452007-08-26 03:42:43 +00001088// ImaginaryLiteral
1089Stmt::child_iterator ImaginaryLiteral::child_begin() {
1090 return reinterpret_cast<Stmt**>(&Val);
1091}
1092Stmt::child_iterator ImaginaryLiteral::child_end() {
1093 return reinterpret_cast<Stmt**>(&Val)+1;
1094}
1095
Ted Kremenek77ed8e42007-08-24 18:13:47 +00001096// StringLiteral
Ted Kremenek9ac59282007-10-18 23:28:49 +00001097Stmt::child_iterator StringLiteral::child_begin() { return child_iterator(); }
1098Stmt::child_iterator StringLiteral::child_end() { return child_iterator(); }
Ted Kremenek77ed8e42007-08-24 18:13:47 +00001099
1100// ParenExpr
1101Stmt::child_iterator ParenExpr::child_begin() {
1102 return reinterpret_cast<Stmt**>(&Val);
1103}
Ted Kremenek77ed8e42007-08-24 18:13:47 +00001104Stmt::child_iterator ParenExpr::child_end() {
Chris Lattner5d661452007-08-26 03:42:43 +00001105 return reinterpret_cast<Stmt**>(&Val)+1;
Ted Kremenek77ed8e42007-08-24 18:13:47 +00001106}
1107
1108// UnaryOperator
1109Stmt::child_iterator UnaryOperator::child_begin() {
Ted Kremenekf816f772007-12-15 00:39:18 +00001110 return reinterpret_cast<Stmt**>(&Val);
Ted Kremenek77ed8e42007-08-24 18:13:47 +00001111}
Ted Kremenek77ed8e42007-08-24 18:13:47 +00001112Stmt::child_iterator UnaryOperator::child_end() {
Ted Kremenekf816f772007-12-15 00:39:18 +00001113 return reinterpret_cast<Stmt**>(&Val+1);
Ted Kremenek77ed8e42007-08-24 18:13:47 +00001114}
1115
1116// SizeOfAlignOfTypeExpr
Ted Kremenek9ac59282007-10-18 23:28:49 +00001117Stmt::child_iterator SizeOfAlignOfTypeExpr::child_begin() {
Ted Kremenek699e9fb2007-12-14 22:52:23 +00001118 // If the type is a VLA type (and not a typedef), the size expression of the
1119 // VLA needs to be treated as an executable expression.
1120 if (VariableArrayType* T = dyn_cast<VariableArrayType>(Ty.getTypePtr()))
1121 return child_iterator(T);
1122 else
1123 return child_iterator();
Ted Kremenek9ac59282007-10-18 23:28:49 +00001124}
1125Stmt::child_iterator SizeOfAlignOfTypeExpr::child_end() {
Ted Kremenek699e9fb2007-12-14 22:52:23 +00001126 return child_iterator();
Ted Kremenek9ac59282007-10-18 23:28:49 +00001127}
Ted Kremenek77ed8e42007-08-24 18:13:47 +00001128
1129// ArraySubscriptExpr
Ted Kremenek1237c672007-08-24 20:06:47 +00001130Stmt::child_iterator ArraySubscriptExpr::child_begin() {
Ted Kremenek77ed8e42007-08-24 18:13:47 +00001131 return reinterpret_cast<Stmt**>(&SubExprs);
1132}
Ted Kremenek1237c672007-08-24 20:06:47 +00001133Stmt::child_iterator ArraySubscriptExpr::child_end() {
Chris Lattner5d661452007-08-26 03:42:43 +00001134 return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR;
Ted Kremenek77ed8e42007-08-24 18:13:47 +00001135}
1136
1137// CallExpr
Ted Kremenek1237c672007-08-24 20:06:47 +00001138Stmt::child_iterator CallExpr::child_begin() {
Ted Kremenek42a29772007-08-27 21:11:44 +00001139 return reinterpret_cast<Stmt**>(&SubExprs[0]);
Ted Kremenek77ed8e42007-08-24 18:13:47 +00001140}
Ted Kremenek1237c672007-08-24 20:06:47 +00001141Stmt::child_iterator CallExpr::child_end() {
Ted Kremenek42a29772007-08-27 21:11:44 +00001142 return reinterpret_cast<Stmt**>(&SubExprs[NumArgs+ARGS_START]);
Ted Kremenek77ed8e42007-08-24 18:13:47 +00001143}
Ted Kremenek1237c672007-08-24 20:06:47 +00001144
1145// MemberExpr
1146Stmt::child_iterator MemberExpr::child_begin() {
1147 return reinterpret_cast<Stmt**>(&Base);
1148}
Ted Kremenek1237c672007-08-24 20:06:47 +00001149Stmt::child_iterator MemberExpr::child_end() {
Chris Lattner5d661452007-08-26 03:42:43 +00001150 return reinterpret_cast<Stmt**>(&Base)+1;
Ted Kremenek1237c672007-08-24 20:06:47 +00001151}
1152
1153// OCUVectorElementExpr
1154Stmt::child_iterator OCUVectorElementExpr::child_begin() {
1155 return reinterpret_cast<Stmt**>(&Base);
1156}
Ted Kremenek1237c672007-08-24 20:06:47 +00001157Stmt::child_iterator OCUVectorElementExpr::child_end() {
Chris Lattner5d661452007-08-26 03:42:43 +00001158 return reinterpret_cast<Stmt**>(&Base)+1;
Ted Kremenek1237c672007-08-24 20:06:47 +00001159}
1160
1161// CompoundLiteralExpr
1162Stmt::child_iterator CompoundLiteralExpr::child_begin() {
1163 return reinterpret_cast<Stmt**>(&Init);
1164}
Ted Kremenek1237c672007-08-24 20:06:47 +00001165Stmt::child_iterator CompoundLiteralExpr::child_end() {
Chris Lattner5d661452007-08-26 03:42:43 +00001166 return reinterpret_cast<Stmt**>(&Init)+1;
Ted Kremenek1237c672007-08-24 20:06:47 +00001167}
1168
1169// ImplicitCastExpr
1170Stmt::child_iterator ImplicitCastExpr::child_begin() {
1171 return reinterpret_cast<Stmt**>(&Op);
1172}
Ted Kremenek1237c672007-08-24 20:06:47 +00001173Stmt::child_iterator ImplicitCastExpr::child_end() {
Chris Lattner5d661452007-08-26 03:42:43 +00001174 return reinterpret_cast<Stmt**>(&Op)+1;
Ted Kremenek1237c672007-08-24 20:06:47 +00001175}
1176
1177// CastExpr
1178Stmt::child_iterator CastExpr::child_begin() {
1179 return reinterpret_cast<Stmt**>(&Op);
1180}
Ted Kremenek1237c672007-08-24 20:06:47 +00001181Stmt::child_iterator CastExpr::child_end() {
Chris Lattner5d661452007-08-26 03:42:43 +00001182 return reinterpret_cast<Stmt**>(&Op)+1;
Ted Kremenek1237c672007-08-24 20:06:47 +00001183}
1184
1185// BinaryOperator
1186Stmt::child_iterator BinaryOperator::child_begin() {
1187 return reinterpret_cast<Stmt**>(&SubExprs);
1188}
Ted Kremenek1237c672007-08-24 20:06:47 +00001189Stmt::child_iterator BinaryOperator::child_end() {
Chris Lattner5d661452007-08-26 03:42:43 +00001190 return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR;
Ted Kremenek1237c672007-08-24 20:06:47 +00001191}
1192
1193// ConditionalOperator
1194Stmt::child_iterator ConditionalOperator::child_begin() {
1195 return reinterpret_cast<Stmt**>(&SubExprs);
1196}
Ted Kremenek1237c672007-08-24 20:06:47 +00001197Stmt::child_iterator ConditionalOperator::child_end() {
Chris Lattner5d661452007-08-26 03:42:43 +00001198 return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR;
Ted Kremenek1237c672007-08-24 20:06:47 +00001199}
1200
1201// AddrLabelExpr
Ted Kremenek9ac59282007-10-18 23:28:49 +00001202Stmt::child_iterator AddrLabelExpr::child_begin() { return child_iterator(); }
1203Stmt::child_iterator AddrLabelExpr::child_end() { return child_iterator(); }
Ted Kremenek1237c672007-08-24 20:06:47 +00001204
Ted Kremenek1237c672007-08-24 20:06:47 +00001205// StmtExpr
1206Stmt::child_iterator StmtExpr::child_begin() {
1207 return reinterpret_cast<Stmt**>(&SubStmt);
1208}
Ted Kremenek1237c672007-08-24 20:06:47 +00001209Stmt::child_iterator StmtExpr::child_end() {
Chris Lattner5d661452007-08-26 03:42:43 +00001210 return reinterpret_cast<Stmt**>(&SubStmt)+1;
Ted Kremenek1237c672007-08-24 20:06:47 +00001211}
1212
1213// TypesCompatibleExpr
Ted Kremenek9ac59282007-10-18 23:28:49 +00001214Stmt::child_iterator TypesCompatibleExpr::child_begin() {
1215 return child_iterator();
1216}
1217
1218Stmt::child_iterator TypesCompatibleExpr::child_end() {
1219 return child_iterator();
1220}
Ted Kremenek1237c672007-08-24 20:06:47 +00001221
1222// ChooseExpr
1223Stmt::child_iterator ChooseExpr::child_begin() {
1224 return reinterpret_cast<Stmt**>(&SubExprs);
1225}
1226
1227Stmt::child_iterator ChooseExpr::child_end() {
Chris Lattner5d661452007-08-26 03:42:43 +00001228 return reinterpret_cast<Stmt**>(&SubExprs)+END_EXPR;
Ted Kremenek1237c672007-08-24 20:06:47 +00001229}
1230
Anders Carlsson7c50aca2007-10-15 20:28:48 +00001231// VAArgExpr
1232Stmt::child_iterator VAArgExpr::child_begin() {
1233 return reinterpret_cast<Stmt**>(&Val);
1234}
1235
1236Stmt::child_iterator VAArgExpr::child_end() {
1237 return reinterpret_cast<Stmt**>(&Val)+1;
1238}
1239
Anders Carlsson66b5a8a2007-08-31 04:56:16 +00001240// InitListExpr
1241Stmt::child_iterator InitListExpr::child_begin() {
1242 return reinterpret_cast<Stmt**>(&InitExprs[0]);
1243}
1244Stmt::child_iterator InitListExpr::child_end() {
1245 return reinterpret_cast<Stmt**>(&InitExprs[NumInits]);
1246}
1247
Ted Kremenek1237c672007-08-24 20:06:47 +00001248// ObjCStringLiteral
Ted Kremenek9ac59282007-10-18 23:28:49 +00001249Stmt::child_iterator ObjCStringLiteral::child_begin() {
1250 return child_iterator();
1251}
1252Stmt::child_iterator ObjCStringLiteral::child_end() {
1253 return child_iterator();
1254}
Ted Kremenek1237c672007-08-24 20:06:47 +00001255
1256// ObjCEncodeExpr
Ted Kremenek9ac59282007-10-18 23:28:49 +00001257Stmt::child_iterator ObjCEncodeExpr::child_begin() { return child_iterator(); }
1258Stmt::child_iterator ObjCEncodeExpr::child_end() { return child_iterator(); }
Ted Kremenek1237c672007-08-24 20:06:47 +00001259
Fariborz Jahanianb62f6812007-10-16 20:40:23 +00001260// ObjCSelectorExpr
Ted Kremenek9ac59282007-10-18 23:28:49 +00001261Stmt::child_iterator ObjCSelectorExpr::child_begin() {
1262 return child_iterator();
1263}
1264Stmt::child_iterator ObjCSelectorExpr::child_end() {
1265 return child_iterator();
1266}
Fariborz Jahanianb62f6812007-10-16 20:40:23 +00001267
Fariborz Jahanian390d50a2007-10-17 16:58:11 +00001268// ObjCProtocolExpr
Ted Kremenek9ac59282007-10-18 23:28:49 +00001269Stmt::child_iterator ObjCProtocolExpr::child_begin() {
1270 return child_iterator();
1271}
1272Stmt::child_iterator ObjCProtocolExpr::child_end() {
1273 return child_iterator();
1274}
Fariborz Jahanian390d50a2007-10-17 16:58:11 +00001275
Steve Naroff563477d2007-09-18 23:55:05 +00001276// ObjCMessageExpr
1277Stmt::child_iterator ObjCMessageExpr::child_begin() {
1278 return reinterpret_cast<Stmt**>(&SubExprs[0]);
1279}
1280Stmt::child_iterator ObjCMessageExpr::child_end() {
Steve Naroff68d331a2007-09-27 14:38:14 +00001281 return reinterpret_cast<Stmt**>(&SubExprs[getNumArgs()+ARGS_START]);
Steve Naroff563477d2007-09-18 23:55:05 +00001282}
1283