blob: 8d10c1fa7f8ce79d551b6288997d2a0943ba22f4 [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
Daniel Dunbar64789f82008-08-11 05:35:13 +000014#include "clang/AST/Expr.h"
Chris Lattner1eee9402008-10-06 06:40:35 +000015#include "clang/AST/APValue.h"
Chris Lattner4b009652007-07-25 00:24:17 +000016#include "clang/AST/ASTContext.h"
Chris Lattner1eee9402008-10-06 06:40:35 +000017#include "clang/AST/DeclObjC.h"
Douglas Gregor6573cfd2008-10-21 23:43:52 +000018#include "clang/AST/DeclCXX.h"
Douglas Gregor279272e2009-02-04 19:02:06 +000019#include "clang/AST/DeclTemplate.h"
Daniel Dunbarde300732008-08-11 04:54:23 +000020#include "clang/AST/RecordLayout.h"
Chris Lattner4b009652007-07-25 00:24:17 +000021#include "clang/AST/StmtVisitor.h"
Chris Lattnerd9ffbc92007-11-27 18:22:04 +000022#include "clang/Basic/TargetInfo.h"
Chris Lattner4b009652007-07-25 00:24:17 +000023using namespace clang;
24
25//===----------------------------------------------------------------------===//
26// Primary Expressions.
27//===----------------------------------------------------------------------===//
28
Chris Lattnere0391b22008-06-07 22:13:43 +000029/// getValueAsApproximateDouble - This returns the value as an inaccurate
30/// double. Note that this may cause loss of precision, but is useful for
31/// debugging dumps, etc.
32double FloatingLiteral::getValueAsApproximateDouble() const {
33 llvm::APFloat V = getValue();
Dale Johannesen2461f612008-10-09 23:02:32 +000034 bool ignored;
35 V.convert(llvm::APFloat::IEEEdouble, llvm::APFloat::rmNearestTiesToEven,
36 &ignored);
Chris Lattnere0391b22008-06-07 22:13:43 +000037 return V.convertToDouble();
38}
39
40
Ted Kremenek4f530a92009-02-06 19:55:15 +000041StringLiteral::StringLiteral(ASTContext& C, const char *strData,
42 unsigned byteLength, bool Wide, QualType t,
43 SourceLocation firstLoc,
Chris Lattner4b009652007-07-25 00:24:17 +000044 SourceLocation lastLoc) :
45 Expr(StringLiteralClass, t) {
46 // OPTIMIZE: could allocate this appended to the StringLiteral.
Ted Kremenek4f530a92009-02-06 19:55:15 +000047 char *AStrData = new (C, 1) char[byteLength];
Chris Lattner4b009652007-07-25 00:24:17 +000048 memcpy(AStrData, strData, byteLength);
49 StrData = AStrData;
50 ByteLength = byteLength;
51 IsWide = Wide;
52 firstTokLoc = firstLoc;
53 lastTokLoc = lastLoc;
54}
55
Ted Kremenek4f530a92009-02-06 19:55:15 +000056void StringLiteral::Destroy(ASTContext &C) {
Ted Kremenek0c97e042009-02-07 01:47:29 +000057 C.Deallocate(const_cast<char*>(StrData));
Ted Kremenek32d760b2009-02-09 17:10:09 +000058 this->~StringLiteral();
59 C.Deallocate(this);
Chris Lattner4b009652007-07-25 00:24:17 +000060}
61
62bool UnaryOperator::isPostfix(Opcode Op) {
63 switch (Op) {
64 case PostInc:
65 case PostDec:
66 return true;
67 default:
68 return false;
69 }
70}
71
Ted Kremenek97318dd2008-07-23 22:18:43 +000072bool UnaryOperator::isPrefix(Opcode Op) {
73 switch (Op) {
74 case PreInc:
75 case PreDec:
76 return true;
77 default:
78 return false;
79 }
80}
81
Chris Lattner4b009652007-07-25 00:24:17 +000082/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
83/// corresponds to, e.g. "sizeof" or "[pre]++".
84const char *UnaryOperator::getOpcodeStr(Opcode Op) {
85 switch (Op) {
86 default: assert(0 && "Unknown unary operator");
87 case PostInc: return "++";
88 case PostDec: return "--";
89 case PreInc: return "++";
90 case PreDec: return "--";
91 case AddrOf: return "&";
92 case Deref: return "*";
93 case Plus: return "+";
94 case Minus: return "-";
95 case Not: return "~";
96 case LNot: return "!";
97 case Real: return "__real";
98 case Imag: return "__imag";
Chris Lattner4b009652007-07-25 00:24:17 +000099 case Extension: return "__extension__";
Chris Lattner0d9bcea2007-08-30 17:45:32 +0000100 case OffsetOf: return "__builtin_offsetof";
Chris Lattner4b009652007-07-25 00:24:17 +0000101 }
102}
103
104//===----------------------------------------------------------------------===//
105// Postfix Operators.
106//===----------------------------------------------------------------------===//
107
Ted Kremenek362abcd2009-02-09 20:51:47 +0000108CallExpr::CallExpr(ASTContext& C, StmtClass SC, Expr *fn, Expr **args,
Ted Kremenek0c97e042009-02-07 01:47:29 +0000109 unsigned numargs, QualType t, SourceLocation rparenloc)
Douglas Gregor1b21c7f2008-12-05 23:32:09 +0000110 : Expr(SC, t,
111 fn->isTypeDependent() || hasAnyTypeDependentArguments(args, numargs),
Chris Lattnerb6eccdc2009-02-16 22:33:34 +0000112 fn->isValueDependent() || hasAnyValueDependentArguments(args,numargs)),
Douglas Gregor1b21c7f2008-12-05 23:32:09 +0000113 NumArgs(numargs) {
Ted Kremenek362abcd2009-02-09 20:51:47 +0000114
115 SubExprs = new (C) Stmt*[numargs+1];
Douglas Gregor65fedaf2008-11-14 16:09:21 +0000116 SubExprs[FN] = fn;
117 for (unsigned i = 0; i != numargs; ++i)
118 SubExprs[i+ARGS_START] = args[i];
Ted Kremenek362abcd2009-02-09 20:51:47 +0000119
Douglas Gregor65fedaf2008-11-14 16:09:21 +0000120 RParenLoc = rparenloc;
121}
Nate Begeman9f3bfb72008-01-17 17:46:27 +0000122
Ted Kremenek362abcd2009-02-09 20:51:47 +0000123CallExpr::CallExpr(ASTContext& C, Expr *fn, Expr **args, unsigned numargs,
124 QualType t, SourceLocation rparenloc)
Douglas Gregor1b21c7f2008-12-05 23:32:09 +0000125 : Expr(CallExprClass, t,
126 fn->isTypeDependent() || hasAnyTypeDependentArguments(args, numargs),
Chris Lattnerb6eccdc2009-02-16 22:33:34 +0000127 fn->isValueDependent() || hasAnyValueDependentArguments(args,numargs)),
Douglas Gregor1b21c7f2008-12-05 23:32:09 +0000128 NumArgs(numargs) {
Ted Kremenek362abcd2009-02-09 20:51:47 +0000129
130 SubExprs = new (C) Stmt*[numargs+1];
Ted Kremeneke4acb9c2007-08-24 18:13:47 +0000131 SubExprs[FN] = fn;
Chris Lattner4b009652007-07-25 00:24:17 +0000132 for (unsigned i = 0; i != numargs; ++i)
Ted Kremeneke4acb9c2007-08-24 18:13:47 +0000133 SubExprs[i+ARGS_START] = args[i];
Ted Kremenek362abcd2009-02-09 20:51:47 +0000134
Chris Lattner4b009652007-07-25 00:24:17 +0000135 RParenLoc = rparenloc;
136}
137
Ted Kremenek362abcd2009-02-09 20:51:47 +0000138void CallExpr::Destroy(ASTContext& C) {
139 DestroyChildren(C);
140 if (SubExprs) C.Deallocate(SubExprs);
141 this->~CallExpr();
142 C.Deallocate(this);
143}
144
Chris Lattnerc257c0d2007-12-28 05:25:02 +0000145/// setNumArgs - This changes the number of arguments present in this call.
146/// Any orphaned expressions are deleted by this, and any new operands are set
147/// to null.
Ted Kremenek0c97e042009-02-07 01:47:29 +0000148void CallExpr::setNumArgs(ASTContext& C, unsigned NumArgs) {
Chris Lattnerc257c0d2007-12-28 05:25:02 +0000149 // No change, just return.
150 if (NumArgs == getNumArgs()) return;
151
152 // If shrinking # arguments, just delete the extras and forgot them.
153 if (NumArgs < getNumArgs()) {
154 for (unsigned i = NumArgs, e = getNumArgs(); i != e; ++i)
Ted Kremenek0c97e042009-02-07 01:47:29 +0000155 getArg(i)->Destroy(C);
Chris Lattnerc257c0d2007-12-28 05:25:02 +0000156 this->NumArgs = NumArgs;
157 return;
158 }
159
160 // Otherwise, we are growing the # arguments. New an bigger argument array.
Ted Kremenek2719e982008-06-17 02:43:46 +0000161 Stmt **NewSubExprs = new Stmt*[NumArgs+1];
Chris Lattnerc257c0d2007-12-28 05:25:02 +0000162 // Copy over args.
163 for (unsigned i = 0; i != getNumArgs()+ARGS_START; ++i)
164 NewSubExprs[i] = SubExprs[i];
165 // Null out new args.
166 for (unsigned i = getNumArgs()+ARGS_START; i != NumArgs+ARGS_START; ++i)
167 NewSubExprs[i] = 0;
168
Ted Kremenek0c97e042009-02-07 01:47:29 +0000169 delete [] SubExprs;
Chris Lattnerc257c0d2007-12-28 05:25:02 +0000170 SubExprs = NewSubExprs;
171 this->NumArgs = NumArgs;
172}
173
Chris Lattnerc24915f2008-10-06 05:00:53 +0000174/// isBuiltinCall - If this is a call to a builtin, return the builtin ID. If
175/// not, return 0.
Douglas Gregorb5af7382009-02-14 18:57:46 +0000176unsigned CallExpr::isBuiltinCall(ASTContext &Context) const {
Steve Naroff44aec4c2008-01-31 01:07:12 +0000177 // All simple function calls (e.g. func()) are implicitly cast to pointer to
178 // function. As a result, we try and obtain the DeclRefExpr from the
179 // ImplicitCastExpr.
180 const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(getCallee());
181 if (!ICE) // FIXME: deal with more complex calls (e.g. (func)(), (*func)()).
Chris Lattnerc24915f2008-10-06 05:00:53 +0000182 return 0;
183
Steve Naroff44aec4c2008-01-31 01:07:12 +0000184 const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(ICE->getSubExpr());
185 if (!DRE)
Chris Lattnerc24915f2008-10-06 05:00:53 +0000186 return 0;
187
Anders Carlsson2ed959f2008-01-31 02:13:57 +0000188 const FunctionDecl *FDecl = dyn_cast<FunctionDecl>(DRE->getDecl());
189 if (!FDecl)
Chris Lattnerc24915f2008-10-06 05:00:53 +0000190 return 0;
191
Douglas Gregorcf4a8892008-11-21 15:30:19 +0000192 if (!FDecl->getIdentifier())
193 return 0;
194
Douglas Gregorb5af7382009-02-14 18:57:46 +0000195 return FDecl->getBuiltinID(Context);
Chris Lattnerc24915f2008-10-06 05:00:53 +0000196}
Anders Carlsson2ed959f2008-01-31 02:13:57 +0000197
Chris Lattnerc24915f2008-10-06 05:00:53 +0000198
Chris Lattner4b009652007-07-25 00:24:17 +0000199/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
200/// corresponds to, e.g. "<<=".
201const char *BinaryOperator::getOpcodeStr(Opcode Op) {
202 switch (Op) {
203 default: assert(0 && "Unknown binary operator");
204 case Mul: return "*";
205 case Div: return "/";
206 case Rem: return "%";
207 case Add: return "+";
208 case Sub: return "-";
209 case Shl: return "<<";
210 case Shr: return ">>";
211 case LT: return "<";
212 case GT: return ">";
213 case LE: return "<=";
214 case GE: return ">=";
215 case EQ: return "==";
216 case NE: return "!=";
217 case And: return "&";
218 case Xor: return "^";
219 case Or: return "|";
220 case LAnd: return "&&";
221 case LOr: return "||";
222 case Assign: return "=";
223 case MulAssign: return "*=";
224 case DivAssign: return "/=";
225 case RemAssign: return "%=";
226 case AddAssign: return "+=";
227 case SubAssign: return "-=";
228 case ShlAssign: return "<<=";
229 case ShrAssign: return ">>=";
230 case AndAssign: return "&=";
231 case XorAssign: return "^=";
232 case OrAssign: return "|=";
233 case Comma: return ",";
234 }
235}
236
Anders Carlsson762b7c72007-08-31 04:56:16 +0000237InitListExpr::InitListExpr(SourceLocation lbraceloc,
Chris Lattner71ca8c82008-10-26 23:43:26 +0000238 Expr **initExprs, unsigned numInits,
Douglas Gregorf603b472009-01-28 21:54:33 +0000239 SourceLocation rbraceloc)
Steve Naroff2e335472008-05-01 02:04:18 +0000240 : Expr(InitListExprClass, QualType()),
Douglas Gregor82462762009-01-29 16:53:55 +0000241 LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), SyntacticForm(0),
Douglas Gregor9fddded2009-01-29 19:42:23 +0000242 UnionFieldInit(0), HadArrayRangeDesignator(false) {
Chris Lattner71ca8c82008-10-26 23:43:26 +0000243
244 InitExprs.insert(InitExprs.end(), initExprs, initExprs+numInits);
Anders Carlsson762b7c72007-08-31 04:56:16 +0000245}
Chris Lattner4b009652007-07-25 00:24:17 +0000246
Douglas Gregorf603b472009-01-28 21:54:33 +0000247void InitListExpr::resizeInits(ASTContext &Context, unsigned NumInits) {
Chris Lattnerb6eccdc2009-02-16 22:33:34 +0000248 for (unsigned Idx = NumInits, LastIdx = InitExprs.size();
249 Idx != LastIdx; ++Idx)
Douglas Gregorf603b472009-01-28 21:54:33 +0000250 delete InitExprs[Idx];
251 InitExprs.resize(NumInits, 0);
252}
253
254Expr *InitListExpr::updateInit(unsigned Init, Expr *expr) {
255 if (Init >= InitExprs.size()) {
256 InitExprs.insert(InitExprs.end(), Init - InitExprs.size() + 1, 0);
257 InitExprs.back() = expr;
258 return 0;
259 }
260
261 Expr *Result = cast_or_null<Expr>(InitExprs[Init]);
262 InitExprs[Init] = expr;
263 return Result;
264}
265
Steve Naroff6f373332008-09-04 15:31:07 +0000266/// getFunctionType - Return the underlying function type for this block.
Steve Naroff52a81c02008-09-03 18:15:37 +0000267///
268const FunctionType *BlockExpr::getFunctionType() const {
269 return getType()->getAsBlockPointerType()->
270 getPointeeType()->getAsFunctionType();
271}
272
Steve Naroff9ac456d2008-10-08 17:01:13 +0000273SourceLocation BlockExpr::getCaretLocation() const {
274 return TheBlock->getCaretLocation();
275}
276const Stmt *BlockExpr::getBody() const { return TheBlock->getBody(); }
277Stmt *BlockExpr::getBody() { return TheBlock->getBody(); }
278
279
Chris Lattner4b009652007-07-25 00:24:17 +0000280//===----------------------------------------------------------------------===//
281// Generic Expression Routines
282//===----------------------------------------------------------------------===//
283
Chris Lattnerd2c66552009-02-14 07:37:35 +0000284/// isUnusedResultAWarning - Return true if this immediate expression should
285/// be warned about if the result is unused. If so, fill in Loc and Ranges
286/// with location to warn on and the source range[s] to report with the
287/// warning.
288bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
289 SourceRange &R2) const {
Chris Lattner4b009652007-07-25 00:24:17 +0000290 switch (getStmtClass()) {
291 default:
Chris Lattnerd2c66552009-02-14 07:37:35 +0000292 Loc = getExprLoc();
293 R1 = getSourceRange();
294 return true;
Chris Lattner4b009652007-07-25 00:24:17 +0000295 case ParenExprClass:
Chris Lattnerd2c66552009-02-14 07:37:35 +0000296 return cast<ParenExpr>(this)->getSubExpr()->
297 isUnusedResultAWarning(Loc, R1, R2);
Chris Lattner4b009652007-07-25 00:24:17 +0000298 case UnaryOperatorClass: {
299 const UnaryOperator *UO = cast<UnaryOperator>(this);
300
301 switch (UO->getOpcode()) {
Chris Lattnerd2c66552009-02-14 07:37:35 +0000302 default: break;
Chris Lattner4b009652007-07-25 00:24:17 +0000303 case UnaryOperator::PostInc:
304 case UnaryOperator::PostDec:
305 case UnaryOperator::PreInc:
Chris Lattnerd2c66552009-02-14 07:37:35 +0000306 case UnaryOperator::PreDec: // ++/--
307 return false; // Not a warning.
Chris Lattner4b009652007-07-25 00:24:17 +0000308 case UnaryOperator::Deref:
309 // Dereferencing a volatile pointer is a side-effect.
Chris Lattnerd2c66552009-02-14 07:37:35 +0000310 if (getType().isVolatileQualified())
311 return false;
312 break;
Chris Lattner4b009652007-07-25 00:24:17 +0000313 case UnaryOperator::Real:
314 case UnaryOperator::Imag:
315 // accessing a piece of a volatile complex is a side-effect.
Chris Lattnerd2c66552009-02-14 07:37:35 +0000316 if (UO->getSubExpr()->getType().isVolatileQualified())
317 return false;
318 break;
Chris Lattner4b009652007-07-25 00:24:17 +0000319 case UnaryOperator::Extension:
Chris Lattnerd2c66552009-02-14 07:37:35 +0000320 return UO->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2);
Chris Lattner4b009652007-07-25 00:24:17 +0000321 }
Chris Lattnerd2c66552009-02-14 07:37:35 +0000322 Loc = UO->getOperatorLoc();
323 R1 = UO->getSubExpr()->getSourceRange();
324 return true;
Chris Lattner4b009652007-07-25 00:24:17 +0000325 }
Chris Lattneref95ffd2007-12-01 06:07:34 +0000326 case BinaryOperatorClass: {
Chris Lattnerd2c66552009-02-14 07:37:35 +0000327 const BinaryOperator *BO = cast<BinaryOperator>(this);
328 // Consider comma to have side effects if the LHS or RHS does.
329 if (BO->getOpcode() == BinaryOperator::Comma)
330 return BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2) ||
331 BO->getLHS()->isUnusedResultAWarning(Loc, R1, R2);
Chris Lattneref95ffd2007-12-01 06:07:34 +0000332
Chris Lattnerd2c66552009-02-14 07:37:35 +0000333 if (BO->isAssignmentOp())
334 return false;
335 Loc = BO->getOperatorLoc();
336 R1 = BO->getLHS()->getSourceRange();
337 R2 = BO->getRHS()->getSourceRange();
338 return true;
Chris Lattneref95ffd2007-12-01 06:07:34 +0000339 }
Chris Lattner06078d22007-08-25 02:00:02 +0000340 case CompoundAssignOperatorClass:
Chris Lattnerd2c66552009-02-14 07:37:35 +0000341 return false;
Chris Lattner4b009652007-07-25 00:24:17 +0000342
Fariborz Jahanian363c59b2007-12-01 19:58:28 +0000343 case ConditionalOperatorClass: {
Chris Lattnerd2c66552009-02-14 07:37:35 +0000344 // The condition must be evaluated, but if either the LHS or RHS is a
345 // warning, warn about them.
Fariborz Jahanian363c59b2007-12-01 19:58:28 +0000346 const ConditionalOperator *Exp = cast<ConditionalOperator>(this);
Chris Lattnerd2c66552009-02-14 07:37:35 +0000347 if (Exp->getLHS()->isUnusedResultAWarning(Loc, R1, R2))
348 return true;
349 return Exp->getRHS()->isUnusedResultAWarning(Loc, R1, R2);
Fariborz Jahanian363c59b2007-12-01 19:58:28 +0000350 }
351
Chris Lattner4b009652007-07-25 00:24:17 +0000352 case MemberExprClass:
Chris Lattnerd2c66552009-02-14 07:37:35 +0000353 // If the base pointer or element is to a volatile pointer/field, accessing
354 // it is a side effect.
355 if (getType().isVolatileQualified())
356 return false;
357 Loc = cast<MemberExpr>(this)->getMemberLoc();
358 R1 = SourceRange(Loc, Loc);
359 R2 = cast<MemberExpr>(this)->getBase()->getSourceRange();
360 return true;
361
Chris Lattner4b009652007-07-25 00:24:17 +0000362 case ArraySubscriptExprClass:
363 // If the base pointer or element is to a volatile pointer/field, accessing
Chris Lattnerd2c66552009-02-14 07:37:35 +0000364 // it is a side effect.
365 if (getType().isVolatileQualified())
366 return false;
367 Loc = cast<ArraySubscriptExpr>(this)->getRBracketLoc();
368 R1 = cast<ArraySubscriptExpr>(this)->getLHS()->getSourceRange();
369 R2 = cast<ArraySubscriptExpr>(this)->getRHS()->getSourceRange();
370 return true;
Eli Friedman21fd0292008-05-27 15:24:04 +0000371
Chris Lattner4b009652007-07-25 00:24:17 +0000372 case CallExprClass:
Chris Lattnerd2c66552009-02-14 07:37:35 +0000373 case CXXOperatorCallExprClass: {
374 // If this is a direct call, get the callee.
375 const CallExpr *CE = cast<CallExpr>(this);
376 const Expr *CalleeExpr = CE->getCallee()->IgnoreParenCasts();
377 if (const DeclRefExpr *CalleeDRE = dyn_cast<DeclRefExpr>(CalleeExpr)) {
378 // If the callee has attribute pure, const, or warn_unused_result, warn
379 // about it. void foo() { strlen("bar"); } should warn.
380 if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CalleeDRE->getDecl()))
381 if (FD->getAttr<WarnUnusedResultAttr>() ||
382 FD->getAttr<PureAttr>() || FD->getAttr<ConstAttr>()) {
383 Loc = CE->getCallee()->getLocStart();
384 R1 = CE->getCallee()->getSourceRange();
385
386 if (unsigned NumArgs = CE->getNumArgs())
387 R2 = SourceRange(CE->getArg(0)->getLocStart(),
388 CE->getArg(NumArgs-1)->getLocEnd());
389 return true;
390 }
391 }
392 return false;
393 }
Chris Lattner99f5f0b2007-09-26 22:06:30 +0000394 case ObjCMessageExprClass:
Chris Lattnerd2c66552009-02-14 07:37:35 +0000395 return false;
Chris Lattner200964f2008-07-26 19:51:01 +0000396 case StmtExprClass: {
397 // Statement exprs don't logically have side effects themselves, but are
398 // sometimes used in macros in ways that give them a type that is unused.
399 // For example ({ blah; foo(); }) will end up with a type if foo has a type.
400 // however, if the result of the stmt expr is dead, we don't want to emit a
401 // warning.
402 const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt();
403 if (!CS->body_empty())
404 if (const Expr *E = dyn_cast<Expr>(CS->body_back()))
Chris Lattnerd2c66552009-02-14 07:37:35 +0000405 return E->isUnusedResultAWarning(Loc, R1, R2);
406
407 Loc = cast<StmtExpr>(this)->getLParenLoc();
408 R1 = getSourceRange();
409 return true;
Chris Lattner200964f2008-07-26 19:51:01 +0000410 }
Douglas Gregor035d0882008-10-28 15:36:24 +0000411 case CStyleCastExprClass:
Chris Lattnerd2c66552009-02-14 07:37:35 +0000412 // If this is a cast to void, check the operand. Otherwise, the result of
413 // the cast is unused.
414 if (getType()->isVoidType())
415 return cast<CastExpr>(this)->getSubExpr()->isUnusedResultAWarning(Loc,
416 R1, R2);
417 Loc = cast<CStyleCastExpr>(this)->getLParenLoc();
418 R1 = cast<CStyleCastExpr>(this)->getSubExpr()->getSourceRange();
419 return true;
Argiris Kirtzidis7a1e7412008-08-22 15:38:55 +0000420 case CXXFunctionalCastExprClass:
Chris Lattner4b009652007-07-25 00:24:17 +0000421 // If this is a cast to void, check the operand. Otherwise, the result of
422 // the cast is unused.
423 if (getType()->isVoidType())
Chris Lattnerd2c66552009-02-14 07:37:35 +0000424 return cast<CastExpr>(this)->getSubExpr()->isUnusedResultAWarning(Loc,
425 R1, R2);
426 Loc = cast<CXXFunctionalCastExpr>(this)->getTypeBeginLoc();
427 R1 = cast<CXXFunctionalCastExpr>(this)->getSubExpr()->getSourceRange();
428 return true;
429
Eli Friedmanb924c7f2008-05-19 21:24:43 +0000430 case ImplicitCastExprClass:
431 // Check the operand, since implicit casts are inserted by Sema
Chris Lattnerd2c66552009-02-14 07:37:35 +0000432 return cast<ImplicitCastExpr>(this)
433 ->getSubExpr()->isUnusedResultAWarning(Loc, R1, R2);
Eli Friedmanb924c7f2008-05-19 21:24:43 +0000434
Chris Lattner3e254fb2008-04-08 04:40:51 +0000435 case CXXDefaultArgExprClass:
Chris Lattnerd2c66552009-02-14 07:37:35 +0000436 return cast<CXXDefaultArgExpr>(this)
437 ->getExpr()->isUnusedResultAWarning(Loc, R1, R2);
Sebastian Redl19fec9d2008-11-21 19:14:01 +0000438
439 case CXXNewExprClass:
440 // FIXME: In theory, there might be new expressions that don't have side
441 // effects (e.g. a placement new with an uninitialized POD).
442 case CXXDeleteExprClass:
Chris Lattnerd2c66552009-02-14 07:37:35 +0000443 return false;
Sebastian Redl19fec9d2008-11-21 19:14:01 +0000444 }
Chris Lattner4b009652007-07-25 00:24:17 +0000445}
446
Douglas Gregor4459bbe2008-10-22 15:04:37 +0000447/// DeclCanBeLvalue - Determine whether the given declaration can be
448/// an lvalue. This is a helper routine for isLvalue.
449static bool DeclCanBeLvalue(const NamedDecl *Decl, ASTContext &Ctx) {
Douglas Gregordd861062008-12-05 18:15:24 +0000450 // C++ [temp.param]p6:
451 // A non-type non-reference template-parameter is not an lvalue.
452 if (const NonTypeTemplateParmDecl *NTTParm
453 = dyn_cast<NonTypeTemplateParmDecl>(Decl))
454 return NTTParm->getType()->isReferenceType();
455
Douglas Gregor8acb7272008-12-11 16:49:14 +0000456 return isa<VarDecl>(Decl) || isa<FieldDecl>(Decl) ||
Douglas Gregor4459bbe2008-10-22 15:04:37 +0000457 // C++ 3.10p2: An lvalue refers to an object or function.
458 (Ctx.getLangOptions().CPlusPlus &&
459 (isa<FunctionDecl>(Decl) || isa<OverloadedFunctionDecl>(Decl)));
460}
461
Chris Lattner4b009652007-07-25 00:24:17 +0000462/// isLvalue - C99 6.3.2.1: an lvalue is an expression with an object type or an
463/// incomplete type other than void. Nonarray expressions that can be lvalues:
464/// - name, where name must be a variable
465/// - e[i]
466/// - (e), where e must be an lvalue
467/// - e.name, where e must be an lvalue
468/// - e->name
469/// - *e, the type of e cannot be a function type
470/// - string-constant
Chris Lattner5bf72022007-10-30 22:53:42 +0000471/// - (__real__ e) and (__imag__ e) where e is an lvalue [GNU extension]
Chris Lattner4b009652007-07-25 00:24:17 +0000472/// - reference type [C++ [expr]]
473///
Chris Lattner25168a52008-07-26 21:30:36 +0000474Expr::isLvalueResult Expr::isLvalue(ASTContext &Ctx) const {
Douglas Gregor6573cfd2008-10-21 23:43:52 +0000475 // first, check the type (C99 6.3.2.1). Expressions with function
476 // type in C are not lvalues, but they can be lvalues in C++.
477 if (!Ctx.getLangOptions().CPlusPlus && TR->isFunctionType())
Chris Lattner4b009652007-07-25 00:24:17 +0000478 return LV_NotObjectType;
479
Steve Naroffec7736d2008-02-10 01:39:04 +0000480 // Allow qualified void which is an incomplete type other than void (yuck).
Chris Lattner25168a52008-07-26 21:30:36 +0000481 if (TR->isVoidType() && !Ctx.getCanonicalType(TR).getCVRQualifiers())
Steve Naroffec7736d2008-02-10 01:39:04 +0000482 return LV_IncompleteVoidType;
483
Douglas Gregor6573cfd2008-10-21 23:43:52 +0000484 /// FIXME: Expressions can't have reference type, so the following
485 /// isn't needed.
Chris Lattner4b009652007-07-25 00:24:17 +0000486 if (TR->isReferenceType()) // C++ [expr]
487 return LV_Valid;
488
489 // the type looks fine, now check the expression
490 switch (getStmtClass()) {
491 case StringLiteralClass: // C99 6.5.1p4
Anders Carlsson9e933a22007-11-30 22:47:59 +0000492 return LV_Valid;
Chris Lattner4b009652007-07-25 00:24:17 +0000493 case ArraySubscriptExprClass: // C99 6.5.3p4 (e1[e2] == (*((e1)+(e2))))
494 // For vectors, make sure base is an lvalue (i.e. not a function call).
495 if (cast<ArraySubscriptExpr>(this)->getBase()->getType()->isVectorType())
Chris Lattner25168a52008-07-26 21:30:36 +0000496 return cast<ArraySubscriptExpr>(this)->getBase()->isLvalue(Ctx);
Chris Lattner4b009652007-07-25 00:24:17 +0000497 return LV_Valid;
Douglas Gregor566782a2009-01-06 05:10:23 +0000498 case DeclRefExprClass:
499 case QualifiedDeclRefExprClass: { // C99 6.5.1p2
Douglas Gregor4459bbe2008-10-22 15:04:37 +0000500 const NamedDecl *RefdDecl = cast<DeclRefExpr>(this)->getDecl();
501 if (DeclCanBeLvalue(RefdDecl, Ctx))
Chris Lattner4b009652007-07-25 00:24:17 +0000502 return LV_Valid;
503 break;
Chris Lattner8c7c6a12008-06-17 18:05:57 +0000504 }
Steve Naroffd6163f32008-09-05 22:11:13 +0000505 case BlockDeclRefExprClass: {
506 const BlockDeclRefExpr *BDR = cast<BlockDeclRefExpr>(this);
Steve Naroff076d6cb2008-09-26 14:41:28 +0000507 if (isa<VarDecl>(BDR->getDecl()))
Steve Naroffd6163f32008-09-05 22:11:13 +0000508 return LV_Valid;
509 break;
510 }
Douglas Gregor82d44772008-12-20 23:49:58 +0000511 case MemberExprClass: {
Chris Lattner4b009652007-07-25 00:24:17 +0000512 const MemberExpr *m = cast<MemberExpr>(this);
Douglas Gregor82d44772008-12-20 23:49:58 +0000513 if (Ctx.getLangOptions().CPlusPlus) { // C++ [expr.ref]p4:
514 NamedDecl *Member = m->getMemberDecl();
515 // C++ [expr.ref]p4:
516 // If E2 is declared to have type "reference to T", then E1.E2
517 // is an lvalue.
518 if (ValueDecl *Value = dyn_cast<ValueDecl>(Member))
519 if (Value->getType()->isReferenceType())
520 return LV_Valid;
521
522 // -- If E2 is a static data member [...] then E1.E2 is an lvalue.
523 if (isa<CXXClassVarDecl>(Member))
524 return LV_Valid;
525
526 // -- If E2 is a non-static data member [...]. If E1 is an
527 // lvalue, then E1.E2 is an lvalue.
528 if (isa<FieldDecl>(Member))
529 return m->isArrow() ? LV_Valid : m->getBase()->isLvalue(Ctx);
530
531 // -- If it refers to a static member function [...], then
532 // E1.E2 is an lvalue.
533 // -- Otherwise, if E1.E2 refers to a non-static member
534 // function [...], then E1.E2 is not an lvalue.
535 if (CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(Member))
536 return Method->isStatic()? LV_Valid : LV_MemberFunction;
537
538 // -- If E2 is a member enumerator [...], the expression E1.E2
539 // is not an lvalue.
540 if (isa<EnumConstantDecl>(Member))
541 return LV_InvalidExpression;
542
543 // Not an lvalue.
544 return LV_InvalidExpression;
545 }
546
547 // C99 6.5.2.3p4
Chris Lattner25168a52008-07-26 21:30:36 +0000548 return m->isArrow() ? LV_Valid : m->getBase()->isLvalue(Ctx);
Chris Lattner4b009652007-07-25 00:24:17 +0000549 }
Chris Lattner5bf72022007-10-30 22:53:42 +0000550 case UnaryOperatorClass:
Chris Lattner4b009652007-07-25 00:24:17 +0000551 if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Deref)
Chris Lattner5bf72022007-10-30 22:53:42 +0000552 return LV_Valid; // C99 6.5.3p4
553
554 if (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Real ||
Chris Lattner1b843a22008-07-25 18:07:19 +0000555 cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Imag ||
556 cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::Extension)
Chris Lattner25168a52008-07-26 21:30:36 +0000557 return cast<UnaryOperator>(this)->getSubExpr()->isLvalue(Ctx); // GNU.
Douglas Gregor4f6904d2008-11-19 15:42:04 +0000558
559 if (Ctx.getLangOptions().CPlusPlus && // C++ [expr.pre.incr]p1
560 (cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::PreInc ||
561 cast<UnaryOperator>(this)->getOpcode() == UnaryOperator::PreDec))
562 return LV_Valid;
Chris Lattner4b009652007-07-25 00:24:17 +0000563 break;
Douglas Gregor70d26122008-11-12 17:17:38 +0000564 case ImplicitCastExprClass:
565 return cast<ImplicitCastExpr>(this)->isLvalueCast()? LV_Valid
566 : LV_InvalidExpression;
Chris Lattner4b009652007-07-25 00:24:17 +0000567 case ParenExprClass: // C99 6.5.1p5
Chris Lattner25168a52008-07-26 21:30:36 +0000568 return cast<ParenExpr>(this)->getSubExpr()->isLvalue(Ctx);
Douglas Gregor70d26122008-11-12 17:17:38 +0000569 case BinaryOperatorClass:
570 case CompoundAssignOperatorClass: {
571 const BinaryOperator *BinOp = cast<BinaryOperator>(this);
Douglas Gregor80723c52008-11-19 17:17:41 +0000572
573 if (Ctx.getLangOptions().CPlusPlus && // C++ [expr.comma]p1
574 BinOp->getOpcode() == BinaryOperator::Comma)
575 return BinOp->getRHS()->isLvalue(Ctx);
576
Sebastian Redl95216a62009-02-07 00:15:38 +0000577 // C++ [expr.mptr.oper]p6
578 if ((BinOp->getOpcode() == BinaryOperator::PtrMemD ||
579 BinOp->getOpcode() == BinaryOperator::PtrMemI) &&
580 !BinOp->getType()->isFunctionType())
581 return BinOp->getLHS()->isLvalue(Ctx);
582
Douglas Gregor3d4492e2008-11-13 20:12:29 +0000583 if (!BinOp->isAssignmentOp())
Douglas Gregor70d26122008-11-12 17:17:38 +0000584 return LV_InvalidExpression;
585
Douglas Gregor3d4492e2008-11-13 20:12:29 +0000586 if (Ctx.getLangOptions().CPlusPlus)
587 // C++ [expr.ass]p1:
588 // The result of an assignment operation [...] is an lvalue.
589 return LV_Valid;
590
591
592 // C99 6.5.16:
593 // An assignment expression [...] is not an lvalue.
594 return LV_InvalidExpression;
Douglas Gregor70d26122008-11-12 17:17:38 +0000595 }
Nate Begemand6d2f772009-01-18 03:20:47 +0000596 // FIXME: OverloadExprClass
Douglas Gregor65fedaf2008-11-14 16:09:21 +0000597 case CallExprClass:
Douglas Gregor3257fb52008-12-22 05:46:06 +0000598 case CXXOperatorCallExprClass:
599 case CXXMemberCallExprClass: {
Douglas Gregor0d5d89d2008-10-28 00:22:11 +0000600 // C++ [expr.call]p10:
601 // A function call is an lvalue if and only if the result type
602 // is a reference.
Douglas Gregor81c29152008-10-29 00:13:59 +0000603 QualType CalleeType = cast<CallExpr>(this)->getCallee()->getType();
Douglas Gregor0d5d89d2008-10-28 00:22:11 +0000604 if (const PointerType *FnTypePtr = CalleeType->getAsPointerType())
Douglas Gregor3257fb52008-12-22 05:46:06 +0000605 CalleeType = FnTypePtr->getPointeeType();
606 if (const FunctionType *FnType = CalleeType->getAsFunctionType())
607 if (FnType->getResultType()->isReferenceType())
608 return LV_Valid;
Douglas Gregor0d5d89d2008-10-28 00:22:11 +0000609
610 break;
611 }
Steve Naroffc7c66532007-12-05 04:00:10 +0000612 case CompoundLiteralExprClass: // C99 6.5.2.5p5
613 return LV_Valid;
Chris Lattnera5f779dc2008-12-12 05:35:08 +0000614 case ChooseExprClass:
615 // __builtin_choose_expr is an lvalue if the selected operand is.
616 if (cast<ChooseExpr>(this)->isConditionTrue(Ctx))
617 return cast<ChooseExpr>(this)->getLHS()->isLvalue(Ctx);
618 else
619 return cast<ChooseExpr>(this)->getRHS()->isLvalue(Ctx);
620
Nate Begemanaf6ed502008-04-18 23:10:10 +0000621 case ExtVectorElementExprClass:
622 if (cast<ExtVectorElementExpr>(this)->containsDuplicateElements())
Steve Naroffba67f692007-07-30 03:29:09 +0000623 return LV_DuplicateVectorComponents;
624 return LV_Valid;
Steve Naroff46f18f22007-11-12 14:34:27 +0000625 case ObjCIvarRefExprClass: // ObjC instance variables are lvalues.
626 return LV_Valid;
Steve Naroff8fff8ce2008-05-30 23:23:16 +0000627 case ObjCPropertyRefExprClass: // FIXME: check if read-only property.
628 return LV_Valid;
Fariborz Jahanianf18d4c82008-11-22 18:39:36 +0000629 case ObjCKVCRefExprClass: // FIXME: check if read-only property.
Chris Lattnera5f779dc2008-12-12 05:35:08 +0000630 return LV_Valid;
Chris Lattner69909292008-08-10 01:53:14 +0000631 case PredefinedExprClass:
Douglas Gregora5b022a2008-11-04 14:32:21 +0000632 return LV_Valid;
Douglas Gregor0d5d89d2008-10-28 00:22:11 +0000633 case VAArgExprClass:
Daniel Dunbar09a82e32009-02-12 09:21:08 +0000634 return LV_NotObjectType;
Chris Lattner3e254fb2008-04-08 04:40:51 +0000635 case CXXDefaultArgExprClass:
Chris Lattner25168a52008-07-26 21:30:36 +0000636 return cast<CXXDefaultArgExpr>(this)->getExpr()->isLvalue(Ctx);
Argiris Kirtzidisc821c862008-09-11 04:22:26 +0000637 case CXXConditionDeclExprClass:
638 return LV_Valid;
Douglas Gregor035d0882008-10-28 15:36:24 +0000639 case CStyleCastExprClass:
Douglas Gregor0d5d89d2008-10-28 00:22:11 +0000640 case CXXFunctionalCastExprClass:
641 case CXXStaticCastExprClass:
642 case CXXDynamicCastExprClass:
643 case CXXReinterpretCastExprClass:
644 case CXXConstCastExprClass:
645 // The result of an explicit cast is an lvalue if the type we are
646 // casting to is a reference type. See C++ [expr.cast]p1,
647 // C++ [expr.static.cast]p2, C++ [expr.dynamic.cast]p2,
648 // C++ [expr.reinterpret.cast]p1, C++ [expr.const.cast]p1.
649 if (cast<ExplicitCastExpr>(this)->getTypeAsWritten()->isReferenceType())
650 return LV_Valid;
651 break;
Sebastian Redlb93b49c2008-11-11 11:37:55 +0000652 case CXXTypeidExprClass:
653 // C++ 5.2.8p1: The result of a typeid expression is an lvalue of ...
654 return LV_Valid;
Chris Lattner4b009652007-07-25 00:24:17 +0000655 default:
656 break;
657 }
658 return LV_InvalidExpression;
659}
660
661/// isModifiableLvalue - C99 6.3.2.1: an lvalue that does not have array type,
662/// does not have an incomplete type, does not have a const-qualified type, and
663/// if it is a structure or union, does not have any member (including,
664/// recursively, any member or element of all contained aggregates or unions)
665/// with a const-qualified type.
Chris Lattner25168a52008-07-26 21:30:36 +0000666Expr::isModifiableLvalueResult Expr::isModifiableLvalue(ASTContext &Ctx) const {
667 isLvalueResult lvalResult = isLvalue(Ctx);
Chris Lattner4b009652007-07-25 00:24:17 +0000668
669 switch (lvalResult) {
Douglas Gregor26a4c5f2008-10-22 00:03:08 +0000670 case LV_Valid:
671 // C++ 3.10p11: Functions cannot be modified, but pointers to
672 // functions can be modifiable.
673 if (Ctx.getLangOptions().CPlusPlus && TR->isFunctionType())
674 return MLV_NotObjectType;
675 break;
676
Chris Lattner4b009652007-07-25 00:24:17 +0000677 case LV_NotObjectType: return MLV_NotObjectType;
678 case LV_IncompleteVoidType: return MLV_IncompleteVoidType;
Steve Naroffba67f692007-07-30 03:29:09 +0000679 case LV_DuplicateVectorComponents: return MLV_DuplicateVectorComponents;
Chris Lattner37fb9402008-11-17 19:51:54 +0000680 case LV_InvalidExpression:
681 // If the top level is a C-style cast, and the subexpression is a valid
682 // lvalue, then this is probably a use of the old-school "cast as lvalue"
683 // GCC extension. We don't support it, but we want to produce good
684 // diagnostics when it happens so that the user knows why.
685 if (const CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(this))
686 if (CE->getSubExpr()->isLvalue(Ctx) == LV_Valid)
687 return MLV_LValueCast;
688 return MLV_InvalidExpression;
Douglas Gregor82d44772008-12-20 23:49:58 +0000689 case LV_MemberFunction: return MLV_MemberFunction;
Chris Lattner4b009652007-07-25 00:24:17 +0000690 }
Chris Lattnera1923f62008-08-04 07:31:14 +0000691
692 QualType CT = Ctx.getCanonicalType(getType());
693
694 if (CT.isConstQualified())
Chris Lattner4b009652007-07-25 00:24:17 +0000695 return MLV_ConstQualified;
Chris Lattnera1923f62008-08-04 07:31:14 +0000696 if (CT->isArrayType())
Chris Lattner4b009652007-07-25 00:24:17 +0000697 return MLV_ArrayType;
Chris Lattnera1923f62008-08-04 07:31:14 +0000698 if (CT->isIncompleteType())
Chris Lattner4b009652007-07-25 00:24:17 +0000699 return MLV_IncompleteType;
700
Chris Lattnera1923f62008-08-04 07:31:14 +0000701 if (const RecordType *r = CT->getAsRecordType()) {
Chris Lattner4b009652007-07-25 00:24:17 +0000702 if (r->hasConstFields())
703 return MLV_ConstQualified;
704 }
Steve Naroff076d6cb2008-09-26 14:41:28 +0000705 // The following is illegal:
706 // void takeclosure(void (^C)(void));
707 // void func() { int x = 1; takeclosure(^{ x = 7 }); }
708 //
709 if (getStmtClass() == BlockDeclRefExprClass) {
710 const BlockDeclRefExpr *BDR = cast<BlockDeclRefExpr>(this);
711 if (!BDR->isByRef() && isa<VarDecl>(BDR->getDecl()))
712 return MLV_NotBlockQualified;
713 }
Fariborz Jahanianf96ee9e2009-01-12 19:55:42 +0000714
Fariborz Jahanianc05da422008-11-22 20:25:50 +0000715 // Assigning to an 'implicit' property?
Fariborz Jahanian48b1a132008-11-25 17:56:43 +0000716 else if (getStmtClass() == ObjCKVCRefExprClass) {
Fariborz Jahanianc05da422008-11-22 20:25:50 +0000717 const ObjCKVCRefExpr* KVCExpr = cast<ObjCKVCRefExpr>(this);
718 if (KVCExpr->getSetterMethod() == 0)
719 return MLV_NoSetterProperty;
720 }
Chris Lattner4b009652007-07-25 00:24:17 +0000721 return MLV_Valid;
722}
723
Ted Kremenek5778d622008-02-27 18:39:48 +0000724/// hasGlobalStorage - Return true if this expression has static storage
Chris Lattner743ec372007-11-27 21:35:27 +0000725/// duration. This means that the address of this expression is a link-time
726/// constant.
Ted Kremenek5778d622008-02-27 18:39:48 +0000727bool Expr::hasGlobalStorage() const {
Chris Lattnerba3ddb22007-11-13 18:05:45 +0000728 switch (getStmtClass()) {
729 default:
730 return false;
Chris Lattner743ec372007-11-27 21:35:27 +0000731 case ParenExprClass:
Ted Kremenek5778d622008-02-27 18:39:48 +0000732 return cast<ParenExpr>(this)->getSubExpr()->hasGlobalStorage();
Chris Lattner743ec372007-11-27 21:35:27 +0000733 case ImplicitCastExprClass:
Ted Kremenek5778d622008-02-27 18:39:48 +0000734 return cast<ImplicitCastExpr>(this)->getSubExpr()->hasGlobalStorage();
Steve Naroffbe37fc02008-01-14 18:19:28 +0000735 case CompoundLiteralExprClass:
736 return cast<CompoundLiteralExpr>(this)->isFileScope();
Douglas Gregor566782a2009-01-06 05:10:23 +0000737 case DeclRefExprClass:
738 case QualifiedDeclRefExprClass: {
Chris Lattnerba3ddb22007-11-13 18:05:45 +0000739 const Decl *D = cast<DeclRefExpr>(this)->getDecl();
740 if (const VarDecl *VD = dyn_cast<VarDecl>(D))
Ted Kremenek5778d622008-02-27 18:39:48 +0000741 return VD->hasGlobalStorage();
Seo Sanghyeone330ae72008-04-04 09:45:30 +0000742 if (isa<FunctionDecl>(D))
743 return true;
Chris Lattnerba3ddb22007-11-13 18:05:45 +0000744 return false;
745 }
Chris Lattnerdb586bf2007-11-28 04:30:09 +0000746 case MemberExprClass: {
Chris Lattnerba3ddb22007-11-13 18:05:45 +0000747 const MemberExpr *M = cast<MemberExpr>(this);
Ted Kremenek5778d622008-02-27 18:39:48 +0000748 return !M->isArrow() && M->getBase()->hasGlobalStorage();
Chris Lattnerdb586bf2007-11-28 04:30:09 +0000749 }
Chris Lattner743ec372007-11-27 21:35:27 +0000750 case ArraySubscriptExprClass:
Ted Kremenek5778d622008-02-27 18:39:48 +0000751 return cast<ArraySubscriptExpr>(this)->getBase()->hasGlobalStorage();
Chris Lattner69909292008-08-10 01:53:14 +0000752 case PredefinedExprClass:
Chris Lattner7e637512008-01-12 08:14:25 +0000753 return true;
Chris Lattner3e254fb2008-04-08 04:40:51 +0000754 case CXXDefaultArgExprClass:
755 return cast<CXXDefaultArgExpr>(this)->getExpr()->hasGlobalStorage();
Chris Lattnerba3ddb22007-11-13 18:05:45 +0000756 }
757}
758
Ted Kremenek87e30c52008-01-17 16:57:34 +0000759Expr* Expr::IgnoreParens() {
760 Expr* E = this;
761 while (ParenExpr* P = dyn_cast<ParenExpr>(E))
762 E = P->getSubExpr();
763
764 return E;
765}
766
Chris Lattner7a48d9c2008-02-13 01:02:39 +0000767/// IgnoreParenCasts - Ignore parentheses and casts. Strip off any ParenExpr
768/// or CastExprs or ImplicitCastExprs, returning their operand.
769Expr *Expr::IgnoreParenCasts() {
770 Expr *E = this;
771 while (true) {
772 if (ParenExpr *P = dyn_cast<ParenExpr>(E))
773 E = P->getSubExpr();
774 else if (CastExpr *P = dyn_cast<CastExpr>(E))
775 E = P->getSubExpr();
Chris Lattner7a48d9c2008-02-13 01:02:39 +0000776 else
777 return E;
778 }
779}
780
Douglas Gregor1b21c7f2008-12-05 23:32:09 +0000781/// hasAnyTypeDependentArguments - Determines if any of the expressions
782/// in Exprs is type-dependent.
783bool Expr::hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs) {
784 for (unsigned I = 0; I < NumExprs; ++I)
785 if (Exprs[I]->isTypeDependent())
786 return true;
787
788 return false;
789}
790
791/// hasAnyValueDependentArguments - Determines if any of the expressions
792/// in Exprs is value-dependent.
793bool Expr::hasAnyValueDependentArguments(Expr** Exprs, unsigned NumExprs) {
794 for (unsigned I = 0; I < NumExprs; ++I)
795 if (Exprs[I]->isValueDependent())
796 return true;
797
798 return false;
799}
800
Eli Friedmandee41122009-01-25 02:32:41 +0000801bool Expr::isConstantInitializer(ASTContext &Ctx) const {
Eli Friedman2b0dec52009-01-25 03:12:18 +0000802 // This function is attempting whether an expression is an initializer
803 // which can be evaluated at compile-time. isEvaluatable handles most
804 // of the cases, but it can't deal with some initializer-specific
805 // expressions, and it can't deal with aggregates; we deal with those here,
806 // and fall back to isEvaluatable for the other cases.
807
Anders Carlssona7fa2aa2008-11-24 05:23:59 +0000808 switch (getStmtClass()) {
Eli Friedman2b0dec52009-01-25 03:12:18 +0000809 default: break;
Anders Carlssona7fa2aa2008-11-24 05:23:59 +0000810 case StringLiteralClass:
Anders Carlssona7fa2aa2008-11-24 05:23:59 +0000811 return true;
Nate Begemand6d2f772009-01-18 03:20:47 +0000812 case CompoundLiteralExprClass: {
813 const Expr *Exp = cast<CompoundLiteralExpr>(this)->getInitializer();
Eli Friedmandee41122009-01-25 02:32:41 +0000814 return Exp->isConstantInitializer(Ctx);
Nate Begemand6d2f772009-01-18 03:20:47 +0000815 }
Anders Carlssona7fa2aa2008-11-24 05:23:59 +0000816 case InitListExprClass: {
817 const InitListExpr *Exp = cast<InitListExpr>(this);
818 unsigned numInits = Exp->getNumInits();
819 for (unsigned i = 0; i < numInits; i++) {
Eli Friedmandee41122009-01-25 02:32:41 +0000820 if (!Exp->getInit(i)->isConstantInitializer(Ctx))
Anders Carlssona7fa2aa2008-11-24 05:23:59 +0000821 return false;
822 }
Eli Friedman2b0dec52009-01-25 03:12:18 +0000823 return true;
Anders Carlssona7fa2aa2008-11-24 05:23:59 +0000824 }
Douglas Gregorc9e012a2009-01-29 17:44:32 +0000825 case ImplicitValueInitExprClass:
826 return true;
Eli Friedman2b0dec52009-01-25 03:12:18 +0000827 case ParenExprClass: {
828 return cast<ParenExpr>(this)->getSubExpr()->isConstantInitializer(Ctx);
829 }
830 case UnaryOperatorClass: {
831 const UnaryOperator* Exp = cast<UnaryOperator>(this);
832 if (Exp->getOpcode() == UnaryOperator::Extension)
833 return Exp->getSubExpr()->isConstantInitializer(Ctx);
834 break;
835 }
836 case CStyleCastExprClass:
837 // Handle casts with a destination that's a struct or union; this
838 // deals with both the gcc no-op struct cast extension and the
839 // cast-to-union extension.
840 if (getType()->isRecordType())
841 return cast<CastExpr>(this)->getSubExpr()->isConstantInitializer(Ctx);
842 break;
Eli Friedmanc8a00142009-01-25 03:27:40 +0000843 case DesignatedInitExprClass:
Sebastian Redl94889622009-01-25 13:34:47 +0000844 return cast<DesignatedInitExpr>(this)->
845 getInit()->isConstantInitializer(Ctx);
Anders Carlssona7fa2aa2008-11-24 05:23:59 +0000846 }
847
Eli Friedman2b0dec52009-01-25 03:12:18 +0000848 return isEvaluatable(Ctx);
Steve Naroff7c9d72d2007-09-02 20:30:18 +0000849}
850
Chris Lattner4b009652007-07-25 00:24:17 +0000851/// isIntegerConstantExpr - this recursive routine will test if an expression is
852/// an integer constant expression. Note: With the introduction of VLA's in
853/// C99 the result of the sizeof operator is no longer always a constant
854/// expression. The generalization of the wording to include any subexpression
855/// that is not evaluated (C99 6.6p3) means that nonconstant subexpressions
856/// can appear as operands to other operators (e.g. &&, ||, ?:). For instance,
Nuno Lopese1b10a12008-07-08 21:13:06 +0000857/// "0 || f()" can be treated as a constant expression. In C90 this expression,
Chris Lattner4b009652007-07-25 00:24:17 +0000858/// occurring in a context requiring a constant, would have been a constraint
859/// violation. FIXME: This routine currently implements C90 semantics.
860/// To properly implement C99 semantics this routine will need to evaluate
861/// expressions involving operators previously mentioned.
862
863/// FIXME: Pass up a reason why! Invalid operation in i-c-e, division by zero,
864/// comma, etc
865///
866/// FIXME: This should ext-warn on overflow during evaluation! ISO C does not
Chris Lattner9d020b32007-09-26 00:47:26 +0000867/// permit this. This includes things like (int)1e1000
Chris Lattner4b009652007-07-25 00:24:17 +0000868///
869/// FIXME: Handle offsetof. Two things to do: Handle GCC's __builtin_offsetof
870/// to support gcc 4.0+ and handle the idiom GCC recognizes with a null pointer
871/// cast+dereference.
872bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
873 SourceLocation *Loc, bool isEvaluated) const {
Eli Friedman14cc7542008-11-13 06:09:17 +0000874 // Pretest for integral type; some parts of the code crash for types that
875 // can't be sized.
876 if (!getType()->isIntegralType()) {
877 if (Loc) *Loc = getLocStart();
878 return false;
879 }
Chris Lattner4b009652007-07-25 00:24:17 +0000880 switch (getStmtClass()) {
881 default:
882 if (Loc) *Loc = getLocStart();
883 return false;
884 case ParenExprClass:
885 return cast<ParenExpr>(this)->getSubExpr()->
886 isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated);
887 case IntegerLiteralClass:
888 Result = cast<IntegerLiteral>(this)->getValue();
889 break;
890 case CharacterLiteralClass: {
891 const CharacterLiteral *CL = cast<CharacterLiteral>(this);
Chris Lattner8cd0e932008-03-05 18:54:05 +0000892 Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
Chris Lattner4b009652007-07-25 00:24:17 +0000893 Result = CL->getValue();
894 Result.setIsUnsigned(!getType()->isSignedIntegerType());
895 break;
896 }
Anders Carlssoned6c2142008-08-23 21:12:35 +0000897 case CXXBoolLiteralExprClass: {
898 const CXXBoolLiteralExpr *BL = cast<CXXBoolLiteralExpr>(this);
899 Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
900 Result = BL->getValue();
901 Result.setIsUnsigned(!getType()->isSignedIntegerType());
902 break;
903 }
Argiris Kirtzidis750eb972008-08-23 19:35:47 +0000904 case CXXZeroInitValueExprClass:
905 Result.clear();
906 break;
Steve Naroffc6f0fd32007-08-02 04:09:23 +0000907 case TypesCompatibleExprClass: {
908 const TypesCompatibleExpr *TCE = cast<TypesCompatibleExpr>(this);
Chris Lattner8cd0e932008-03-05 18:54:05 +0000909 Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
Daniel Dunbarda8ebd22008-10-24 08:07:57 +0000910 // Per gcc docs "this built-in function ignores top level
911 // qualifiers". We need to use the canonical version to properly
912 // be able to strip CRV qualifiers from the type.
913 QualType T0 = Ctx.getCanonicalType(TCE->getArgType1());
914 QualType T1 = Ctx.getCanonicalType(TCE->getArgType2());
915 Result = Ctx.typesAreCompatible(T0.getUnqualifiedType(),
916 T1.getUnqualifiedType());
Steve Naroff1200b5a2007-08-02 00:13:27 +0000917 break;
Steve Naroffc6f0fd32007-08-02 04:09:23 +0000918 }
Douglas Gregor65fedaf2008-11-14 16:09:21 +0000919 case CallExprClass:
920 case CXXOperatorCallExprClass: {
Steve Naroff8d3b1702007-08-08 22:15:55 +0000921 const CallExpr *CE = cast<CallExpr>(this);
Chris Lattner8cd0e932008-03-05 18:54:05 +0000922 Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
Chris Lattner1eee9402008-10-06 06:40:35 +0000923
924 // If this is a call to a builtin function, constant fold it otherwise
925 // reject it.
Douglas Gregorb5af7382009-02-14 18:57:46 +0000926 if (CE->isBuiltinCall(Ctx)) {
Anders Carlsson8c3de802008-12-19 20:58:05 +0000927 EvalResult EvalResult;
928 if (CE->Evaluate(EvalResult, Ctx)) {
929 assert(!EvalResult.HasSideEffects &&
930 "Foldable builtin call should not have side effects!");
931 Result = EvalResult.Val.getInt();
Chris Lattner1eee9402008-10-06 06:40:35 +0000932 break; // It is a constant, expand it.
933 }
934 }
935
Steve Naroff8d3b1702007-08-08 22:15:55 +0000936 if (Loc) *Loc = getLocStart();
937 return false;
938 }
Chris Lattner4b009652007-07-25 00:24:17 +0000939 case DeclRefExprClass:
Douglas Gregor566782a2009-01-06 05:10:23 +0000940 case QualifiedDeclRefExprClass:
Chris Lattner4b009652007-07-25 00:24:17 +0000941 if (const EnumConstantDecl *D =
942 dyn_cast<EnumConstantDecl>(cast<DeclRefExpr>(this)->getDecl())) {
943 Result = D->getInitVal();
944 break;
945 }
Sebastian Redl57ef46a2009-02-07 13:06:23 +0000946 if (Ctx.getLangOptions().CPlusPlus &&
947 getType().getCVRQualifiers() == QualType::Const) {
948 // C++ 7.1.5.1p2
949 // A variable of non-volatile const-qualified integral or enumeration
950 // type initialized by an ICE can be used in ICEs.
951 if (const VarDecl *Dcl =
952 dyn_cast<VarDecl>(cast<DeclRefExpr>(this)->getDecl())) {
953 if (const Expr *Init = Dcl->getInit())
954 return Init->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated);
955 }
956 }
Chris Lattner4b009652007-07-25 00:24:17 +0000957 if (Loc) *Loc = getLocStart();
958 return false;
959 case UnaryOperatorClass: {
960 const UnaryOperator *Exp = cast<UnaryOperator>(this);
961
Sebastian Redl0cb7c872008-11-11 17:56:53 +0000962 // Get the operand value. If this is offsetof, do not evalute the
Chris Lattner4b009652007-07-25 00:24:17 +0000963 // operand. This affects C99 6.6p3.
Sebastian Redl0cb7c872008-11-11 17:56:53 +0000964 if (!Exp->isOffsetOfOp() && !Exp->getSubExpr()->
965 isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated))
Chris Lattner4b009652007-07-25 00:24:17 +0000966 return false;
967
968 switch (Exp->getOpcode()) {
969 // Address, indirect, pre/post inc/dec, etc are not valid constant exprs.
970 // See C99 6.6p3.
971 default:
972 if (Loc) *Loc = Exp->getOperatorLoc();
973 return false;
974 case UnaryOperator::Extension:
975 return true; // FIXME: this is wrong.
Chris Lattner4b009652007-07-25 00:24:17 +0000976 case UnaryOperator::LNot: {
Chris Lattnerf00fdc02008-01-25 19:16:19 +0000977 bool Val = Result == 0;
Chris Lattner8cd0e932008-03-05 18:54:05 +0000978 Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
Chris Lattner4b009652007-07-25 00:24:17 +0000979 Result = Val;
980 break;
981 }
982 case UnaryOperator::Plus:
983 break;
984 case UnaryOperator::Minus:
985 Result = -Result;
986 break;
987 case UnaryOperator::Not:
988 Result = ~Result;
989 break;
Anders Carlsson52774ad2008-01-29 15:56:48 +0000990 case UnaryOperator::OffsetOf:
Daniel Dunbar461d08c2008-08-28 18:42:20 +0000991 Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
Anders Carlsson52774ad2008-01-29 15:56:48 +0000992 Result = Exp->evaluateOffsetOf(Ctx);
Chris Lattner4b009652007-07-25 00:24:17 +0000993 }
994 break;
995 }
Sebastian Redl0cb7c872008-11-11 17:56:53 +0000996 case SizeOfAlignOfExprClass: {
997 const SizeOfAlignOfExpr *Exp = cast<SizeOfAlignOfExpr>(this);
Chris Lattner20515462008-02-21 05:45:29 +0000998
999 // Return the result in the right width.
Chris Lattner8cd0e932008-03-05 18:54:05 +00001000 Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(getType())));
Chris Lattner20515462008-02-21 05:45:29 +00001001
Sebastian Redl0cb7c872008-11-11 17:56:53 +00001002 QualType ArgTy = Exp->getTypeOfArgument();
Chris Lattner20515462008-02-21 05:45:29 +00001003 // sizeof(void) and __alignof__(void) = 1 as a gcc extension.
Sebastian Redl0cb7c872008-11-11 17:56:53 +00001004 if (ArgTy->isVoidType()) {
Chris Lattner20515462008-02-21 05:45:29 +00001005 Result = 1;
1006 break;
1007 }
1008
1009 // alignof always evaluates to a constant, sizeof does if arg is not VLA.
Sebastian Redl0cb7c872008-11-11 17:56:53 +00001010 if (Exp->isSizeOf() && !ArgTy->isConstantSizeType()) {
Chris Lattnerb3ff0822007-12-18 07:15:40 +00001011 if (Loc) *Loc = Exp->getOperatorLoc();
Chris Lattner4b009652007-07-25 00:24:17 +00001012 return false;
Chris Lattnerb3ff0822007-12-18 07:15:40 +00001013 }
Chris Lattner4b009652007-07-25 00:24:17 +00001014
Chris Lattner4b009652007-07-25 00:24:17 +00001015 // Get information about the size or align.
Sebastian Redl0cb7c872008-11-11 17:56:53 +00001016 if (ArgTy->isFunctionType()) {
Chris Lattnerd4dc2672008-01-02 21:54:09 +00001017 // GCC extension: sizeof(function) = 1.
1018 Result = Exp->isSizeOf() ? 1 : 4;
Anders Carlsson8d2b2b72008-02-16 01:20:23 +00001019 } else {
Chris Lattner8cd0e932008-03-05 18:54:05 +00001020 unsigned CharSize = Ctx.Target.getCharWidth();
Anders Carlsson8d2b2b72008-02-16 01:20:23 +00001021 if (Exp->isSizeOf())
Sebastian Redl0cb7c872008-11-11 17:56:53 +00001022 Result = Ctx.getTypeSize(ArgTy) / CharSize;
Anders Carlsson8d2b2b72008-02-16 01:20:23 +00001023 else
Sebastian Redl0cb7c872008-11-11 17:56:53 +00001024 Result = Ctx.getTypeAlign(ArgTy) / CharSize;
Ted Kremeneka9d0fd92007-12-17 17:38:43 +00001025 }
Chris Lattner4b009652007-07-25 00:24:17 +00001026 break;
1027 }
1028 case BinaryOperatorClass: {
1029 const BinaryOperator *Exp = cast<BinaryOperator>(this);
Daniel Dunbarf173b2c2008-09-22 23:53:24 +00001030 llvm::APSInt LHS, RHS;
1031
1032 // Initialize result to have correct signedness and width.
1033 Result = llvm::APSInt(static_cast<uint32_t>(Ctx.getTypeSize(getType())),
Chris Lattnerb6eccdc2009-02-16 22:33:34 +00001034 !getType()->isSignedIntegerType());
Eli Friedmanb2935ab2008-11-13 02:13:11 +00001035
Chris Lattner4b009652007-07-25 00:24:17 +00001036 // The LHS of a constant expr is always evaluated and needed.
Daniel Dunbarf173b2c2008-09-22 23:53:24 +00001037 if (!Exp->getLHS()->isIntegerConstantExpr(LHS, Ctx, Loc, isEvaluated))
Chris Lattner4b009652007-07-25 00:24:17 +00001038 return false;
1039
Chris Lattner4b009652007-07-25 00:24:17 +00001040 // The short-circuiting &&/|| operators don't necessarily evaluate their
1041 // RHS. Make sure to pass isEvaluated down correctly.
1042 if (Exp->isLogicalOp()) {
1043 bool RHSEval;
1044 if (Exp->getOpcode() == BinaryOperator::LAnd)
Daniel Dunbarf173b2c2008-09-22 23:53:24 +00001045 RHSEval = LHS != 0;
Chris Lattner4b009652007-07-25 00:24:17 +00001046 else {
1047 assert(Exp->getOpcode() == BinaryOperator::LOr &&"Unexpected logical");
Daniel Dunbarf173b2c2008-09-22 23:53:24 +00001048 RHSEval = LHS == 0;
Chris Lattner4b009652007-07-25 00:24:17 +00001049 }
1050
1051 if (!Exp->getRHS()->isIntegerConstantExpr(RHS, Ctx, Loc,
1052 isEvaluated & RHSEval))
1053 return false;
1054 } else {
1055 if (!Exp->getRHS()->isIntegerConstantExpr(RHS, Ctx, Loc, isEvaluated))
1056 return false;
1057 }
1058
1059 switch (Exp->getOpcode()) {
1060 default:
1061 if (Loc) *Loc = getLocStart();
1062 return false;
1063 case BinaryOperator::Mul:
Daniel Dunbarf173b2c2008-09-22 23:53:24 +00001064 Result = LHS * RHS;
Chris Lattner4b009652007-07-25 00:24:17 +00001065 break;
1066 case BinaryOperator::Div:
1067 if (RHS == 0) {
1068 if (!isEvaluated) break;
1069 if (Loc) *Loc = getLocStart();
1070 return false;
1071 }
Daniel Dunbarf173b2c2008-09-22 23:53:24 +00001072 Result = LHS / RHS;
Chris Lattner4b009652007-07-25 00:24:17 +00001073 break;
1074 case BinaryOperator::Rem:
1075 if (RHS == 0) {
1076 if (!isEvaluated) break;
1077 if (Loc) *Loc = getLocStart();
1078 return false;
1079 }
Daniel Dunbarf173b2c2008-09-22 23:53:24 +00001080 Result = LHS % RHS;
Chris Lattner4b009652007-07-25 00:24:17 +00001081 break;
Daniel Dunbarf173b2c2008-09-22 23:53:24 +00001082 case BinaryOperator::Add: Result = LHS + RHS; break;
1083 case BinaryOperator::Sub: Result = LHS - RHS; break;
Chris Lattner4b009652007-07-25 00:24:17 +00001084 case BinaryOperator::Shl:
Daniel Dunbarf173b2c2008-09-22 23:53:24 +00001085 Result = LHS <<
1086 static_cast<uint32_t>(RHS.getLimitedValue(LHS.getBitWidth()-1));
1087 break;
Chris Lattner4b009652007-07-25 00:24:17 +00001088 case BinaryOperator::Shr:
Daniel Dunbarf173b2c2008-09-22 23:53:24 +00001089 Result = LHS >>
1090 static_cast<uint32_t>(RHS.getLimitedValue(LHS.getBitWidth()-1));
Chris Lattner4b009652007-07-25 00:24:17 +00001091 break;
Daniel Dunbarf173b2c2008-09-22 23:53:24 +00001092 case BinaryOperator::LT: Result = LHS < RHS; break;
1093 case BinaryOperator::GT: Result = LHS > RHS; break;
1094 case BinaryOperator::LE: Result = LHS <= RHS; break;
1095 case BinaryOperator::GE: Result = LHS >= RHS; break;
1096 case BinaryOperator::EQ: Result = LHS == RHS; break;
1097 case BinaryOperator::NE: Result = LHS != RHS; break;
1098 case BinaryOperator::And: Result = LHS & RHS; break;
1099 case BinaryOperator::Xor: Result = LHS ^ RHS; break;
1100 case BinaryOperator::Or: Result = LHS | RHS; break;
Chris Lattner4b009652007-07-25 00:24:17 +00001101 case BinaryOperator::LAnd:
Daniel Dunbarf173b2c2008-09-22 23:53:24 +00001102 Result = LHS != 0 && RHS != 0;
Chris Lattner4b009652007-07-25 00:24:17 +00001103 break;
1104 case BinaryOperator::LOr:
Daniel Dunbarf173b2c2008-09-22 23:53:24 +00001105 Result = LHS != 0 || RHS != 0;
Chris Lattner4b009652007-07-25 00:24:17 +00001106 break;
Eli Friedmanb2935ab2008-11-13 02:13:11 +00001107
1108 case BinaryOperator::Comma:
1109 // C99 6.6p3: "shall not contain assignment, ..., or comma operators,
1110 // *except* when they are contained within a subexpression that is not
1111 // evaluated". Note that Assignment can never happen due to constraints
1112 // on the LHS subexpr, so we don't need to check it here.
1113 if (isEvaluated) {
1114 if (Loc) *Loc = getLocStart();
1115 return false;
1116 }
1117
1118 // The result of the constant expr is the RHS.
1119 Result = RHS;
1120 return true;
Chris Lattner4b009652007-07-25 00:24:17 +00001121 }
1122
1123 assert(!Exp->isAssignmentOp() && "LHS can't be a constant expr!");
1124 break;
1125 }
1126 case ImplicitCastExprClass:
Douglas Gregor035d0882008-10-28 15:36:24 +00001127 case CStyleCastExprClass:
Argiris Kirtzidis7a1e7412008-08-22 15:38:55 +00001128 case CXXFunctionalCastExprClass: {
Argiris Kirtzidisc45e2fb2008-08-18 23:01:59 +00001129 const Expr *SubExpr = cast<CastExpr>(this)->getSubExpr();
1130 SourceLocation CastLoc = getLocStart();
Chris Lattner4b009652007-07-25 00:24:17 +00001131
1132 // C99 6.6p6: shall only convert arithmetic types to integer types.
1133 if (!SubExpr->getType()->isArithmeticType() ||
1134 !getType()->isIntegerType()) {
1135 if (Loc) *Loc = SubExpr->getLocStart();
1136 return false;
1137 }
Chris Lattner76a0c1b2007-09-22 19:04:13 +00001138
Chris Lattner8cd0e932008-03-05 18:54:05 +00001139 uint32_t DestWidth = static_cast<uint32_t>(Ctx.getTypeSize(getType()));
Chris Lattner76a0c1b2007-09-22 19:04:13 +00001140
Chris Lattner4b009652007-07-25 00:24:17 +00001141 // Handle simple integer->integer casts.
1142 if (SubExpr->getType()->isIntegerType()) {
1143 if (!SubExpr->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated))
1144 return false;
1145
1146 // Figure out if this is a truncate, extend or noop cast.
Chris Lattner4b009652007-07-25 00:24:17 +00001147 // If the input is signed, do a sign extend, noop, or truncate.
Chris Lattner000c4102008-01-09 18:59:34 +00001148 if (getType()->isBooleanType()) {
1149 // Conversion to bool compares against zero.
1150 Result = Result != 0;
1151 Result.zextOrTrunc(DestWidth);
1152 } else if (SubExpr->getType()->isSignedIntegerType())
Chris Lattner4b009652007-07-25 00:24:17 +00001153 Result.sextOrTrunc(DestWidth);
1154 else // If the input is unsigned, do a zero extend, noop, or truncate.
1155 Result.zextOrTrunc(DestWidth);
1156 break;
1157 }
1158
1159 // Allow floating constants that are the immediate operands of casts or that
1160 // are parenthesized.
1161 const Expr *Operand = SubExpr;
1162 while (const ParenExpr *PE = dyn_cast<ParenExpr>(Operand))
1163 Operand = PE->getSubExpr();
Chris Lattner76a0c1b2007-09-22 19:04:13 +00001164
1165 // If this isn't a floating literal, we can't handle it.
1166 const FloatingLiteral *FL = dyn_cast<FloatingLiteral>(Operand);
1167 if (!FL) {
1168 if (Loc) *Loc = Operand->getLocStart();
1169 return false;
Chris Lattner4b009652007-07-25 00:24:17 +00001170 }
Chris Lattner000c4102008-01-09 18:59:34 +00001171
1172 // If the destination is boolean, compare against zero.
1173 if (getType()->isBooleanType()) {
1174 Result = !FL->getValue().isZero();
1175 Result.zextOrTrunc(DestWidth);
1176 break;
1177 }
Chris Lattner76a0c1b2007-09-22 19:04:13 +00001178
1179 // Determine whether we are converting to unsigned or signed.
1180 bool DestSigned = getType()->isSignedIntegerType();
Chris Lattner9d020b32007-09-26 00:47:26 +00001181
1182 // TODO: Warn on overflow, but probably not here: isIntegerConstantExpr can
1183 // be called multiple times per AST.
Dale Johannesen2461f612008-10-09 23:02:32 +00001184 uint64_t Space[4];
1185 bool ignored;
Chris Lattner9d020b32007-09-26 00:47:26 +00001186 (void)FL->getValue().convertToInteger(Space, DestWidth, DestSigned,
Dale Johannesen2461f612008-10-09 23:02:32 +00001187 llvm::APFloat::rmTowardZero,
1188 &ignored);
Chris Lattner76a0c1b2007-09-22 19:04:13 +00001189 Result = llvm::APInt(DestWidth, 4, Space);
1190 break;
Chris Lattner4b009652007-07-25 00:24:17 +00001191 }
1192 case ConditionalOperatorClass: {
1193 const ConditionalOperator *Exp = cast<ConditionalOperator>(this);
1194
Chris Lattner45e71bf2008-12-12 06:55:44 +00001195 const Expr *Cond = Exp->getCond();
1196
1197 if (!Cond->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated))
Chris Lattner4b009652007-07-25 00:24:17 +00001198 return false;
1199
1200 const Expr *TrueExp = Exp->getLHS();
1201 const Expr *FalseExp = Exp->getRHS();
1202 if (Result == 0) std::swap(TrueExp, FalseExp);
1203
Chris Lattner45e71bf2008-12-12 06:55:44 +00001204 // If the condition (ignoring parens) is a __builtin_constant_p call,
1205 // then only the true side is actually considered in an integer constant
Chris Lattner2a6a5b32008-12-12 18:00:51 +00001206 // expression, and it is fully evaluated. This is an important GNU
1207 // extension. See GCC PR38377 for discussion.
Chris Lattner45e71bf2008-12-12 06:55:44 +00001208 if (const CallExpr *CallCE = dyn_cast<CallExpr>(Cond->IgnoreParenCasts()))
Douglas Gregorb5af7382009-02-14 18:57:46 +00001209 if (CallCE->isBuiltinCall(Ctx) == Builtin::BI__builtin_constant_p) {
Chris Lattner2a6a5b32008-12-12 18:00:51 +00001210 EvalResult EVResult;
1211 if (!Evaluate(EVResult, Ctx) || EVResult.HasSideEffects)
1212 return false;
1213 assert(EVResult.Val.isInt() && "FP conditional expr not expected");
1214 Result = EVResult.Val.getInt();
1215 if (Loc) *Loc = EVResult.DiagLoc;
1216 return true;
1217 }
Chris Lattner45e71bf2008-12-12 06:55:44 +00001218
Chris Lattner4b009652007-07-25 00:24:17 +00001219 // Evaluate the false one first, discard the result.
Anders Carlsson37365fc2007-11-30 19:04:31 +00001220 if (FalseExp && !FalseExp->isIntegerConstantExpr(Result, Ctx, Loc, false))
Chris Lattner4b009652007-07-25 00:24:17 +00001221 return false;
1222 // Evalute the true one, capture the result.
Anders Carlsson37365fc2007-11-30 19:04:31 +00001223 if (TrueExp &&
1224 !TrueExp->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated))
Chris Lattner4b009652007-07-25 00:24:17 +00001225 return false;
1226 break;
1227 }
Chris Lattner3e254fb2008-04-08 04:40:51 +00001228 case CXXDefaultArgExprClass:
1229 return cast<CXXDefaultArgExpr>(this)
1230 ->isIntegerConstantExpr(Result, Ctx, Loc, isEvaluated);
Sebastian Redl39c0f6f2009-01-05 20:52:13 +00001231
1232 case UnaryTypeTraitExprClass:
1233 Result = cast<UnaryTypeTraitExpr>(this)->Evaluate();
1234 return true;
Chris Lattner4b009652007-07-25 00:24:17 +00001235 }
1236
1237 // Cases that are valid constant exprs fall through to here.
1238 Result.setIsUnsigned(getType()->isUnsignedIntegerType());
1239 return true;
1240}
1241
Chris Lattner4b009652007-07-25 00:24:17 +00001242/// isNullPointerConstant - C99 6.3.2.3p3 - Return true if this is either an
1243/// integer constant expression with the value zero, or if this is one that is
1244/// cast to void*.
Anders Carlsson2ce7c3d2008-12-01 02:13:57 +00001245bool Expr::isNullPointerConstant(ASTContext &Ctx) const
1246{
Sebastian Redl9ac68aa2008-10-31 14:43:28 +00001247 // Strip off a cast to void*, if it exists. Except in C++.
Argiris Kirtzidisc45e2fb2008-08-18 23:01:59 +00001248 if (const ExplicitCastExpr *CE = dyn_cast<ExplicitCastExpr>(this)) {
Sebastian Redl3768d272008-11-04 11:45:54 +00001249 if (!Ctx.getLangOptions().CPlusPlus) {
Sebastian Redl9ac68aa2008-10-31 14:43:28 +00001250 // Check that it is a cast to void*.
1251 if (const PointerType *PT = CE->getType()->getAsPointerType()) {
1252 QualType Pointee = PT->getPointeeType();
1253 if (Pointee.getCVRQualifiers() == 0 &&
1254 Pointee->isVoidType() && // to void*
1255 CE->getSubExpr()->getType()->isIntegerType()) // from int.
Anders Carlssonf8aa8702008-12-01 06:28:23 +00001256 return CE->getSubExpr()->isNullPointerConstant(Ctx);
Sebastian Redl9ac68aa2008-10-31 14:43:28 +00001257 }
Chris Lattner4b009652007-07-25 00:24:17 +00001258 }
Steve Naroffa2e53222008-01-14 16:10:57 +00001259 } else if (const ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(this)) {
1260 // Ignore the ImplicitCastExpr type entirely.
Anders Carlssonf8aa8702008-12-01 06:28:23 +00001261 return ICE->getSubExpr()->isNullPointerConstant(Ctx);
Steve Naroffa2e53222008-01-14 16:10:57 +00001262 } else if (const ParenExpr *PE = dyn_cast<ParenExpr>(this)) {
1263 // Accept ((void*)0) as a null pointer constant, as many other
1264 // implementations do.
Anders Carlssonf8aa8702008-12-01 06:28:23 +00001265 return PE->getSubExpr()->isNullPointerConstant(Ctx);
Chris Lattner97316c02008-04-10 02:22:51 +00001266 } else if (const CXXDefaultArgExpr *DefaultArg
1267 = dyn_cast<CXXDefaultArgExpr>(this)) {
Chris Lattner3e254fb2008-04-08 04:40:51 +00001268 // See through default argument expressions
Anders Carlssonf8aa8702008-12-01 06:28:23 +00001269 return DefaultArg->getExpr()->isNullPointerConstant(Ctx);
Douglas Gregorad4b3792008-11-29 04:51:27 +00001270 } else if (isa<GNUNullExpr>(this)) {
1271 // The GNU __null extension is always a null pointer constant.
1272 return true;
Steve Narofff33a9852008-01-14 02:53:34 +00001273 }
Douglas Gregorad4b3792008-11-29 04:51:27 +00001274
Steve Naroffa2e53222008-01-14 16:10:57 +00001275 // This expression must be an integer type.
1276 if (!getType()->isIntegerType())
1277 return false;
1278
Chris Lattner4b009652007-07-25 00:24:17 +00001279 // If we have an integer constant expression, we need to *evaluate* it and
1280 // test for the value 0.
Anders Carlssonf8aa8702008-12-01 06:28:23 +00001281 // FIXME: We should probably return false if we're compiling in strict mode
1282 // and Diag is not null (this indicates that the value was foldable but not
1283 // an ICE.
1284 EvalResult Result;
Anders Carlsson2ce7c3d2008-12-01 02:13:57 +00001285 return Evaluate(Result, Ctx) && !Result.HasSideEffects &&
Anders Carlssonf8aa8702008-12-01 06:28:23 +00001286 Result.Val.isInt() && Result.Val.getInt() == 0;
Chris Lattner4b009652007-07-25 00:24:17 +00001287}
Steve Naroffc11705f2007-07-28 23:10:27 +00001288
Douglas Gregor81c29152008-10-29 00:13:59 +00001289/// isBitField - Return true if this expression is a bit-field.
1290bool Expr::isBitField() {
1291 Expr *E = this->IgnoreParenCasts();
1292 if (MemberExpr *MemRef = dyn_cast<MemberExpr>(E))
Douglas Gregor82d44772008-12-20 23:49:58 +00001293 if (FieldDecl *Field = dyn_cast<FieldDecl>(MemRef->getMemberDecl()))
1294 return Field->isBitField();
Douglas Gregor81c29152008-10-29 00:13:59 +00001295 return false;
1296}
1297
Chris Lattner98e7fcc2009-02-16 22:14:05 +00001298/// isArrow - Return true if the base expression is a pointer to vector,
1299/// return false if the base expression is a vector.
1300bool ExtVectorElementExpr::isArrow() const {
1301 return getBase()->getType()->isPointerType();
1302}
1303
Nate Begemanaf6ed502008-04-18 23:10:10 +00001304unsigned ExtVectorElementExpr::getNumElements() const {
Nate Begemanc8e51f82008-05-09 06:41:27 +00001305 if (const VectorType *VT = getType()->getAsVectorType())
1306 return VT->getNumElements();
1307 return 1;
Chris Lattner50547852007-08-03 16:00:20 +00001308}
1309
Nate Begemanc8e51f82008-05-09 06:41:27 +00001310/// containsDuplicateElements - Return true if any element access is repeated.
Nate Begemanaf6ed502008-04-18 23:10:10 +00001311bool ExtVectorElementExpr::containsDuplicateElements() const {
Steve Naroffba67f692007-07-30 03:29:09 +00001312 const char *compStr = Accessor.getName();
Chris Lattner58d3fa52008-11-19 07:55:04 +00001313 unsigned length = Accessor.getLength();
Nate Begemana8e117c2009-01-18 02:01:21 +00001314
1315 // Halving swizzles do not contain duplicate elements.
1316 if (!strcmp(compStr, "hi") || !strcmp(compStr, "lo") ||
1317 !strcmp(compStr, "even") || !strcmp(compStr, "odd"))
1318 return false;
1319
1320 // Advance past s-char prefix on hex swizzles.
1321 if (*compStr == 's') {
1322 compStr++;
1323 length--;
1324 }
Steve Naroffba67f692007-07-30 03:29:09 +00001325
Chris Lattner58d3fa52008-11-19 07:55:04 +00001326 for (unsigned i = 0; i != length-1; i++) {
Steve Naroffba67f692007-07-30 03:29:09 +00001327 const char *s = compStr+i;
1328 for (const char c = *s++; *s; s++)
1329 if (c == *s)
1330 return true;
1331 }
1332 return false;
1333}
Chris Lattner42158e72007-08-02 23:36:59 +00001334
Nate Begemanc8e51f82008-05-09 06:41:27 +00001335/// getEncodedElementAccess - We encode the fields as a llvm ConstantArray.
Nate Begemana1ae7442008-05-13 21:03:02 +00001336void ExtVectorElementExpr::getEncodedElementAccess(
1337 llvm::SmallVectorImpl<unsigned> &Elts) const {
Chris Lattner58d3fa52008-11-19 07:55:04 +00001338 const char *compStr = Accessor.getName();
Nate Begeman1486b502009-01-18 01:47:54 +00001339 if (*compStr == 's')
1340 compStr++;
1341
1342 bool isHi = !strcmp(compStr, "hi");
1343 bool isLo = !strcmp(compStr, "lo");
1344 bool isEven = !strcmp(compStr, "even");
1345 bool isOdd = !strcmp(compStr, "odd");
1346
Nate Begemanc8e51f82008-05-09 06:41:27 +00001347 for (unsigned i = 0, e = getNumElements(); i != e; ++i) {
1348 uint64_t Index;
1349
1350 if (isHi)
1351 Index = e + i;
1352 else if (isLo)
1353 Index = i;
1354 else if (isEven)
1355 Index = 2 * i;
1356 else if (isOdd)
1357 Index = 2 * i + 1;
1358 else
1359 Index = ExtVectorType::getAccessorIdx(compStr[i]);
Chris Lattner42158e72007-08-02 23:36:59 +00001360
Nate Begemana1ae7442008-05-13 21:03:02 +00001361 Elts.push_back(Index);
Chris Lattner42158e72007-08-02 23:36:59 +00001362 }
Nate Begemanc8e51f82008-05-09 06:41:27 +00001363}
1364
Steve Naroff4ed9d662007-09-27 14:38:14 +00001365// constructor for instance messages.
Steve Naroff6cb1d362007-09-28 22:22:11 +00001366ObjCMessageExpr::ObjCMessageExpr(Expr *receiver, Selector selInfo,
Ted Kremenek42730c52008-01-07 19:49:32 +00001367 QualType retType, ObjCMethodDecl *mproto,
Steve Naroff1e1c3912007-11-03 16:37:59 +00001368 SourceLocation LBrac, SourceLocation RBrac,
Steve Naroff9f176d12007-11-15 13:05:42 +00001369 Expr **ArgExprs, unsigned nargs)
Steve Naroff1e1c3912007-11-03 16:37:59 +00001370 : Expr(ObjCMessageExprClass, retType), SelName(selInfo),
Ted Kremenekd029a6f2008-05-01 17:26:20 +00001371 MethodProto(mproto) {
Steve Naroff9f176d12007-11-15 13:05:42 +00001372 NumArgs = nargs;
Ted Kremenek2719e982008-06-17 02:43:46 +00001373 SubExprs = new Stmt*[NumArgs+1];
Steve Naroff4ed9d662007-09-27 14:38:14 +00001374 SubExprs[RECEIVER] = receiver;
Steve Naroff9f176d12007-11-15 13:05:42 +00001375 if (NumArgs) {
1376 for (unsigned i = 0; i != NumArgs; ++i)
Steve Naroff4ed9d662007-09-27 14:38:14 +00001377 SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]);
1378 }
Steve Naroffc39ca262007-09-18 23:55:05 +00001379 LBracloc = LBrac;
1380 RBracloc = RBrac;
1381}
1382
Steve Naroff4ed9d662007-09-27 14:38:14 +00001383// constructor for class messages.
1384// FIXME: clsName should be typed to ObjCInterfaceType
Steve Naroff6cb1d362007-09-28 22:22:11 +00001385ObjCMessageExpr::ObjCMessageExpr(IdentifierInfo *clsName, Selector selInfo,
Ted Kremenek42730c52008-01-07 19:49:32 +00001386 QualType retType, ObjCMethodDecl *mproto,
Steve Naroff1e1c3912007-11-03 16:37:59 +00001387 SourceLocation LBrac, SourceLocation RBrac,
Steve Naroff9f176d12007-11-15 13:05:42 +00001388 Expr **ArgExprs, unsigned nargs)
Steve Naroff1e1c3912007-11-03 16:37:59 +00001389 : Expr(ObjCMessageExprClass, retType), SelName(selInfo),
Ted Kremenekd029a6f2008-05-01 17:26:20 +00001390 MethodProto(mproto) {
Steve Naroff9f176d12007-11-15 13:05:42 +00001391 NumArgs = nargs;
Ted Kremenek2719e982008-06-17 02:43:46 +00001392 SubExprs = new Stmt*[NumArgs+1];
Ted Kremenekee2c9fd2008-06-24 15:50:53 +00001393 SubExprs[RECEIVER] = (Expr*) ((uintptr_t) clsName | IsClsMethDeclUnknown);
Steve Naroff9f176d12007-11-15 13:05:42 +00001394 if (NumArgs) {
1395 for (unsigned i = 0; i != NumArgs; ++i)
Steve Naroff4ed9d662007-09-27 14:38:14 +00001396 SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]);
1397 }
Steve Naroffc39ca262007-09-18 23:55:05 +00001398 LBracloc = LBrac;
1399 RBracloc = RBrac;
1400}
1401
Ted Kremenekee2c9fd2008-06-24 15:50:53 +00001402// constructor for class messages.
1403ObjCMessageExpr::ObjCMessageExpr(ObjCInterfaceDecl *cls, Selector selInfo,
1404 QualType retType, ObjCMethodDecl *mproto,
1405 SourceLocation LBrac, SourceLocation RBrac,
1406 Expr **ArgExprs, unsigned nargs)
1407: Expr(ObjCMessageExprClass, retType), SelName(selInfo),
1408MethodProto(mproto) {
1409 NumArgs = nargs;
1410 SubExprs = new Stmt*[NumArgs+1];
1411 SubExprs[RECEIVER] = (Expr*) ((uintptr_t) cls | IsClsMethDeclKnown);
1412 if (NumArgs) {
1413 for (unsigned i = 0; i != NumArgs; ++i)
1414 SubExprs[i+ARGS_START] = static_cast<Expr *>(ArgExprs[i]);
1415 }
1416 LBracloc = LBrac;
1417 RBracloc = RBrac;
1418}
1419
1420ObjCMessageExpr::ClassInfo ObjCMessageExpr::getClassInfo() const {
1421 uintptr_t x = (uintptr_t) SubExprs[RECEIVER];
1422 switch (x & Flags) {
1423 default:
1424 assert(false && "Invalid ObjCMessageExpr.");
1425 case IsInstMeth:
1426 return ClassInfo(0, 0);
1427 case IsClsMethDeclUnknown:
1428 return ClassInfo(0, (IdentifierInfo*) (x & ~Flags));
1429 case IsClsMethDeclKnown: {
1430 ObjCInterfaceDecl* D = (ObjCInterfaceDecl*) (x & ~Flags);
1431 return ClassInfo(D, D->getIdentifier());
1432 }
1433 }
1434}
1435
Chris Lattnerf624cd22007-10-25 00:29:32 +00001436bool ChooseExpr::isConditionTrue(ASTContext &C) const {
Daniel Dunbar7cbcbf42008-08-13 23:47:13 +00001437 return getCond()->getIntegerConstantExprValue(C) != 0;
Chris Lattnerf624cd22007-10-25 00:29:32 +00001438}
1439
Chris Lattnera5f779dc2008-12-12 05:35:08 +00001440static int64_t evaluateOffsetOf(ASTContext& C, const Expr *E) {
Anders Carlsson52774ad2008-01-29 15:56:48 +00001441 if (const MemberExpr *ME = dyn_cast<MemberExpr>(E)) {
1442 QualType Ty = ME->getBase()->getType();
1443
1444 RecordDecl *RD = Ty->getAsRecordType()->getDecl();
Chris Lattner8cd0e932008-03-05 18:54:05 +00001445 const ASTRecordLayout &RL = C.getASTRecordLayout(RD);
Douglas Gregor82d44772008-12-20 23:49:58 +00001446 if (FieldDecl *FD = dyn_cast<FieldDecl>(ME->getMemberDecl())) {
1447 // FIXME: This is linear time. And the fact that we're indexing
1448 // into the layout by position in the record means that we're
1449 // either stuck numbering the fields in the AST or we have to keep
1450 // the linear search (yuck and yuck).
1451 unsigned i = 0;
1452 for (RecordDecl::field_iterator Field = RD->field_begin(),
1453 FieldEnd = RD->field_end();
1454 Field != FieldEnd; (void)++Field, ++i) {
1455 if (*Field == FD)
1456 break;
1457 }
1458
1459 return RL.getFieldOffset(i) + evaluateOffsetOf(C, ME->getBase());
Anders Carlsson52774ad2008-01-29 15:56:48 +00001460 }
Anders Carlsson52774ad2008-01-29 15:56:48 +00001461 } else if (const ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
1462 const Expr *Base = ASE->getBase();
Anders Carlsson52774ad2008-01-29 15:56:48 +00001463
Chris Lattner8cd0e932008-03-05 18:54:05 +00001464 int64_t size = C.getTypeSize(ASE->getType());
Daniel Dunbar7cbcbf42008-08-13 23:47:13 +00001465 size *= ASE->getIdx()->getIntegerConstantExprValue(C).getSExtValue();
Anders Carlsson52774ad2008-01-29 15:56:48 +00001466
1467 return size + evaluateOffsetOf(C, Base);
1468 } else if (isa<CompoundLiteralExpr>(E))
1469 return 0;
1470
1471 assert(0 && "Unknown offsetof subexpression!");
1472 return 0;
1473}
1474
1475int64_t UnaryOperator::evaluateOffsetOf(ASTContext& C) const
1476{
1477 assert(Opc == OffsetOf && "Unary operator not offsetof!");
1478
Chris Lattner8cd0e932008-03-05 18:54:05 +00001479 unsigned CharSize = C.Target.getCharWidth();
Ted Kremenek2719e982008-06-17 02:43:46 +00001480 return ::evaluateOffsetOf(C, cast<Expr>(Val)) / CharSize;
Anders Carlsson52774ad2008-01-29 15:56:48 +00001481}
1482
Sebastian Redl0cb7c872008-11-11 17:56:53 +00001483void SizeOfAlignOfExpr::Destroy(ASTContext& C) {
1484 // Override default behavior of traversing children. If this has a type
1485 // operand and the type is a variable-length array, the child iteration
1486 // will iterate over the size expression. However, this expression belongs
1487 // to the type, not to this, so we don't want to delete it.
1488 // We still want to delete this expression.
Ted Kremenek0c97e042009-02-07 01:47:29 +00001489 if (isArgumentType()) {
1490 this->~SizeOfAlignOfExpr();
1491 C.Deallocate(this);
1492 }
Sebastian Redl0cb7c872008-11-11 17:56:53 +00001493 else
1494 Expr::Destroy(C);
Daniel Dunbar7cfb85b2008-08-28 18:02:04 +00001495}
1496
Ted Kremenekf1a67122009-02-09 17:08:14 +00001497void OverloadExpr::Destroy(ASTContext& C) {
1498 DestroyChildren(C);
1499 C.Deallocate(SubExprs);
1500 this->~OverloadExpr();
1501 C.Deallocate(this);
1502}
1503
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001504//===----------------------------------------------------------------------===//
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +00001505// DesignatedInitExpr
1506//===----------------------------------------------------------------------===//
1507
1508IdentifierInfo *DesignatedInitExpr::Designator::getFieldName() {
1509 assert(Kind == FieldDesignator && "Only valid on a field designator");
1510 if (Field.NameOrField & 0x01)
1511 return reinterpret_cast<IdentifierInfo *>(Field.NameOrField&~0x01);
1512 else
1513 return getField()->getIdentifier();
1514}
1515
1516DesignatedInitExpr *
1517DesignatedInitExpr::Create(ASTContext &C, Designator *Designators,
1518 unsigned NumDesignators,
1519 Expr **IndexExprs, unsigned NumIndexExprs,
1520 SourceLocation ColonOrEqualLoc,
1521 bool UsesColonSyntax, Expr *Init) {
Steve Naroff207b9ec2009-01-27 23:20:32 +00001522 void *Mem = C.Allocate(sizeof(DesignatedInitExpr) +
1523 sizeof(Designator) * NumDesignators +
1524 sizeof(Stmt *) * (NumIndexExprs + 1), 8);
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +00001525 DesignatedInitExpr *DIE
1526 = new (Mem) DesignatedInitExpr(C.VoidTy, NumDesignators,
1527 ColonOrEqualLoc, UsesColonSyntax,
1528 NumIndexExprs + 1);
1529
1530 // Fill in the designators
1531 unsigned ExpectedNumSubExprs = 0;
1532 designators_iterator Desig = DIE->designators_begin();
1533 for (unsigned Idx = 0; Idx < NumDesignators; ++Idx, ++Desig) {
1534 new (static_cast<void*>(Desig)) Designator(Designators[Idx]);
1535 if (Designators[Idx].isArrayDesignator())
1536 ++ExpectedNumSubExprs;
1537 else if (Designators[Idx].isArrayRangeDesignator())
1538 ExpectedNumSubExprs += 2;
1539 }
1540 assert(ExpectedNumSubExprs == NumIndexExprs && "Wrong number of indices!");
1541
1542 // Fill in the subexpressions, including the initializer expression.
1543 child_iterator Child = DIE->child_begin();
1544 *Child++ = Init;
1545 for (unsigned Idx = 0; Idx < NumIndexExprs; ++Idx, ++Child)
1546 *Child = IndexExprs[Idx];
1547
1548 return DIE;
1549}
1550
1551SourceRange DesignatedInitExpr::getSourceRange() const {
1552 SourceLocation StartLoc;
Chris Lattnerb6eccdc2009-02-16 22:33:34 +00001553 Designator &First =
1554 *const_cast<DesignatedInitExpr*>(this)->designators_begin();
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +00001555 if (First.isFieldDesignator()) {
1556 if (UsesColonSyntax)
1557 StartLoc = SourceLocation::getFromRawEncoding(First.Field.FieldLoc);
1558 else
1559 StartLoc = SourceLocation::getFromRawEncoding(First.Field.DotLoc);
1560 } else
Chris Lattnerb6eccdc2009-02-16 22:33:34 +00001561 StartLoc =
1562 SourceLocation::getFromRawEncoding(First.ArrayOrRange.LBracketLoc);
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +00001563 return SourceRange(StartLoc, getInit()->getSourceRange().getEnd());
1564}
1565
Chris Lattnerb6eccdc2009-02-16 22:33:34 +00001566DesignatedInitExpr::designators_iterator
1567DesignatedInitExpr::designators_begin() {
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +00001568 char* Ptr = static_cast<char*>(static_cast<void *>(this));
1569 Ptr += sizeof(DesignatedInitExpr);
1570 return static_cast<Designator*>(static_cast<void*>(Ptr));
1571}
1572
1573DesignatedInitExpr::designators_iterator DesignatedInitExpr::designators_end() {
1574 return designators_begin() + NumDesignators;
1575}
1576
1577Expr *DesignatedInitExpr::getArrayIndex(const Designator& D) {
1578 assert(D.Kind == Designator::ArrayDesignator && "Requires array designator");
1579 char* Ptr = static_cast<char*>(static_cast<void *>(this));
1580 Ptr += sizeof(DesignatedInitExpr);
1581 Ptr += sizeof(Designator) * NumDesignators;
1582 Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr));
1583 return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1));
1584}
1585
1586Expr *DesignatedInitExpr::getArrayRangeStart(const Designator& D) {
1587 assert(D.Kind == Designator::ArrayRangeDesignator &&
1588 "Requires array range designator");
1589 char* Ptr = static_cast<char*>(static_cast<void *>(this));
1590 Ptr += sizeof(DesignatedInitExpr);
1591 Ptr += sizeof(Designator) * NumDesignators;
1592 Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr));
1593 return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 1));
1594}
1595
1596Expr *DesignatedInitExpr::getArrayRangeEnd(const Designator& D) {
1597 assert(D.Kind == Designator::ArrayRangeDesignator &&
1598 "Requires array range designator");
1599 char* Ptr = static_cast<char*>(static_cast<void *>(this));
1600 Ptr += sizeof(DesignatedInitExpr);
1601 Ptr += sizeof(Designator) * NumDesignators;
1602 Stmt **SubExprs = reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr));
1603 return cast<Expr>(*(SubExprs + D.ArrayOrRange.Index + 2));
1604}
1605
1606//===----------------------------------------------------------------------===//
Ted Kremenekb30de272008-10-27 18:40:21 +00001607// ExprIterator.
1608//===----------------------------------------------------------------------===//
1609
1610Expr* ExprIterator::operator[](size_t idx) { return cast<Expr>(I[idx]); }
1611Expr* ExprIterator::operator*() const { return cast<Expr>(*I); }
1612Expr* ExprIterator::operator->() const { return cast<Expr>(*I); }
1613const Expr* ConstExprIterator::operator[](size_t idx) const {
1614 return cast<Expr>(I[idx]);
1615}
1616const Expr* ConstExprIterator::operator*() const { return cast<Expr>(*I); }
1617const Expr* ConstExprIterator::operator->() const { return cast<Expr>(*I); }
1618
1619//===----------------------------------------------------------------------===//
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001620// Child Iterators for iterating over subexpressions/substatements
1621//===----------------------------------------------------------------------===//
1622
1623// DeclRefExpr
Ted Kremeneka6478552007-10-18 23:28:49 +00001624Stmt::child_iterator DeclRefExpr::child_begin() { return child_iterator(); }
1625Stmt::child_iterator DeclRefExpr::child_end() { return child_iterator(); }
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001626
Steve Naroff5eb2a4a2007-11-12 14:29:37 +00001627// ObjCIvarRefExpr
Ted Kremenek2719e982008-06-17 02:43:46 +00001628Stmt::child_iterator ObjCIvarRefExpr::child_begin() { return &Base; }
1629Stmt::child_iterator ObjCIvarRefExpr::child_end() { return &Base+1; }
Steve Naroff5eb2a4a2007-11-12 14:29:37 +00001630
Steve Naroff6f786252008-06-02 23:03:37 +00001631// ObjCPropertyRefExpr
Ted Kremenek2719e982008-06-17 02:43:46 +00001632Stmt::child_iterator ObjCPropertyRefExpr::child_begin() { return &Base; }
1633Stmt::child_iterator ObjCPropertyRefExpr::child_end() { return &Base+1; }
Steve Naroff05391d22008-05-30 00:40:33 +00001634
Fariborz Jahanianf18d4c82008-11-22 18:39:36 +00001635// ObjCKVCRefExpr
1636Stmt::child_iterator ObjCKVCRefExpr::child_begin() { return &Base; }
1637Stmt::child_iterator ObjCKVCRefExpr::child_end() { return &Base+1; }
1638
Douglas Gregord8606632008-11-04 14:56:14 +00001639// ObjCSuperExpr
1640Stmt::child_iterator ObjCSuperExpr::child_begin() { return child_iterator(); }
1641Stmt::child_iterator ObjCSuperExpr::child_end() { return child_iterator(); }
1642
Chris Lattner69909292008-08-10 01:53:14 +00001643// PredefinedExpr
1644Stmt::child_iterator PredefinedExpr::child_begin() { return child_iterator(); }
1645Stmt::child_iterator PredefinedExpr::child_end() { return child_iterator(); }
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001646
1647// IntegerLiteral
Ted Kremeneka6478552007-10-18 23:28:49 +00001648Stmt::child_iterator IntegerLiteral::child_begin() { return child_iterator(); }
1649Stmt::child_iterator IntegerLiteral::child_end() { return child_iterator(); }
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001650
1651// CharacterLiteral
Chris Lattnerb6eccdc2009-02-16 22:33:34 +00001652Stmt::child_iterator CharacterLiteral::child_begin() { return child_iterator();}
Ted Kremeneka6478552007-10-18 23:28:49 +00001653Stmt::child_iterator CharacterLiteral::child_end() { return child_iterator(); }
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001654
1655// FloatingLiteral
Ted Kremeneka6478552007-10-18 23:28:49 +00001656Stmt::child_iterator FloatingLiteral::child_begin() { return child_iterator(); }
1657Stmt::child_iterator FloatingLiteral::child_end() { return child_iterator(); }
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001658
Chris Lattner1de66eb2007-08-26 03:42:43 +00001659// ImaginaryLiteral
Ted Kremenek2719e982008-06-17 02:43:46 +00001660Stmt::child_iterator ImaginaryLiteral::child_begin() { return &Val; }
1661Stmt::child_iterator ImaginaryLiteral::child_end() { return &Val+1; }
Chris Lattner1de66eb2007-08-26 03:42:43 +00001662
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001663// StringLiteral
Ted Kremeneka6478552007-10-18 23:28:49 +00001664Stmt::child_iterator StringLiteral::child_begin() { return child_iterator(); }
1665Stmt::child_iterator StringLiteral::child_end() { return child_iterator(); }
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001666
1667// ParenExpr
Ted Kremenek2719e982008-06-17 02:43:46 +00001668Stmt::child_iterator ParenExpr::child_begin() { return &Val; }
1669Stmt::child_iterator ParenExpr::child_end() { return &Val+1; }
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001670
1671// UnaryOperator
Ted Kremenek2719e982008-06-17 02:43:46 +00001672Stmt::child_iterator UnaryOperator::child_begin() { return &Val; }
1673Stmt::child_iterator UnaryOperator::child_end() { return &Val+1; }
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001674
Sebastian Redl0cb7c872008-11-11 17:56:53 +00001675// SizeOfAlignOfExpr
1676Stmt::child_iterator SizeOfAlignOfExpr::child_begin() {
1677 // If this is of a type and the type is a VLA type (and not a typedef), the
1678 // size expression of the VLA needs to be treated as an executable expression.
1679 // Why isn't this weirdness documented better in StmtIterator?
1680 if (isArgumentType()) {
1681 if (VariableArrayType* T = dyn_cast<VariableArrayType>(
1682 getArgumentType().getTypePtr()))
1683 return child_iterator(T);
1684 return child_iterator();
1685 }
Sebastian Redl9f81c3f2008-12-03 23:17:54 +00001686 return child_iterator(&Argument.Ex);
Ted Kremeneka6478552007-10-18 23:28:49 +00001687}
Sebastian Redl0cb7c872008-11-11 17:56:53 +00001688Stmt::child_iterator SizeOfAlignOfExpr::child_end() {
1689 if (isArgumentType())
1690 return child_iterator();
Sebastian Redl9f81c3f2008-12-03 23:17:54 +00001691 return child_iterator(&Argument.Ex + 1);
Ted Kremeneka6478552007-10-18 23:28:49 +00001692}
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001693
1694// ArraySubscriptExpr
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001695Stmt::child_iterator ArraySubscriptExpr::child_begin() {
Ted Kremenek2719e982008-06-17 02:43:46 +00001696 return &SubExprs[0];
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001697}
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001698Stmt::child_iterator ArraySubscriptExpr::child_end() {
Ted Kremenek2719e982008-06-17 02:43:46 +00001699 return &SubExprs[0]+END_EXPR;
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001700}
1701
1702// CallExpr
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001703Stmt::child_iterator CallExpr::child_begin() {
Ted Kremenek2719e982008-06-17 02:43:46 +00001704 return &SubExprs[0];
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001705}
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001706Stmt::child_iterator CallExpr::child_end() {
Ted Kremenek2719e982008-06-17 02:43:46 +00001707 return &SubExprs[0]+NumArgs+ARGS_START;
Ted Kremeneke4acb9c2007-08-24 18:13:47 +00001708}
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001709
1710// MemberExpr
Ted Kremenek2719e982008-06-17 02:43:46 +00001711Stmt::child_iterator MemberExpr::child_begin() { return &Base; }
1712Stmt::child_iterator MemberExpr::child_end() { return &Base+1; }
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001713
Nate Begemanaf6ed502008-04-18 23:10:10 +00001714// ExtVectorElementExpr
Ted Kremenek2719e982008-06-17 02:43:46 +00001715Stmt::child_iterator ExtVectorElementExpr::child_begin() { return &Base; }
1716Stmt::child_iterator ExtVectorElementExpr::child_end() { return &Base+1; }
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001717
1718// CompoundLiteralExpr
Ted Kremenek2719e982008-06-17 02:43:46 +00001719Stmt::child_iterator CompoundLiteralExpr::child_begin() { return &Init; }
1720Stmt::child_iterator CompoundLiteralExpr::child_end() { return &Init+1; }
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001721
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001722// CastExpr
Ted Kremenek2719e982008-06-17 02:43:46 +00001723Stmt::child_iterator CastExpr::child_begin() { return &Op; }
1724Stmt::child_iterator CastExpr::child_end() { return &Op+1; }
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001725
1726// BinaryOperator
1727Stmt::child_iterator BinaryOperator::child_begin() {
Ted Kremenek2719e982008-06-17 02:43:46 +00001728 return &SubExprs[0];
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001729}
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001730Stmt::child_iterator BinaryOperator::child_end() {
Ted Kremenek2719e982008-06-17 02:43:46 +00001731 return &SubExprs[0]+END_EXPR;
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001732}
1733
1734// ConditionalOperator
1735Stmt::child_iterator ConditionalOperator::child_begin() {
Ted Kremenek2719e982008-06-17 02:43:46 +00001736 return &SubExprs[0];
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001737}
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001738Stmt::child_iterator ConditionalOperator::child_end() {
Ted Kremenek2719e982008-06-17 02:43:46 +00001739 return &SubExprs[0]+END_EXPR;
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001740}
1741
1742// AddrLabelExpr
Ted Kremeneka6478552007-10-18 23:28:49 +00001743Stmt::child_iterator AddrLabelExpr::child_begin() { return child_iterator(); }
1744Stmt::child_iterator AddrLabelExpr::child_end() { return child_iterator(); }
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001745
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001746// StmtExpr
Ted Kremenek2719e982008-06-17 02:43:46 +00001747Stmt::child_iterator StmtExpr::child_begin() { return &SubStmt; }
1748Stmt::child_iterator StmtExpr::child_end() { return &SubStmt+1; }
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001749
1750// TypesCompatibleExpr
Ted Kremeneka6478552007-10-18 23:28:49 +00001751Stmt::child_iterator TypesCompatibleExpr::child_begin() {
1752 return child_iterator();
1753}
1754
1755Stmt::child_iterator TypesCompatibleExpr::child_end() {
1756 return child_iterator();
1757}
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001758
1759// ChooseExpr
Ted Kremenek2719e982008-06-17 02:43:46 +00001760Stmt::child_iterator ChooseExpr::child_begin() { return &SubExprs[0]; }
1761Stmt::child_iterator ChooseExpr::child_end() { return &SubExprs[0]+END_EXPR; }
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001762
Douglas Gregorad4b3792008-11-29 04:51:27 +00001763// GNUNullExpr
1764Stmt::child_iterator GNUNullExpr::child_begin() { return child_iterator(); }
1765Stmt::child_iterator GNUNullExpr::child_end() { return child_iterator(); }
1766
Nate Begeman9f3bfb72008-01-17 17:46:27 +00001767// OverloadExpr
Ted Kremenek2719e982008-06-17 02:43:46 +00001768Stmt::child_iterator OverloadExpr::child_begin() { return &SubExprs[0]; }
1769Stmt::child_iterator OverloadExpr::child_end() { return &SubExprs[0]+NumExprs; }
Nate Begeman9f3bfb72008-01-17 17:46:27 +00001770
Eli Friedmand0e9d092008-05-14 19:38:39 +00001771// ShuffleVectorExpr
1772Stmt::child_iterator ShuffleVectorExpr::child_begin() {
Ted Kremenek2719e982008-06-17 02:43:46 +00001773 return &SubExprs[0];
Eli Friedmand0e9d092008-05-14 19:38:39 +00001774}
1775Stmt::child_iterator ShuffleVectorExpr::child_end() {
Ted Kremenek2719e982008-06-17 02:43:46 +00001776 return &SubExprs[0]+NumExprs;
Eli Friedmand0e9d092008-05-14 19:38:39 +00001777}
1778
Anders Carlsson36760332007-10-15 20:28:48 +00001779// VAArgExpr
Ted Kremenek2719e982008-06-17 02:43:46 +00001780Stmt::child_iterator VAArgExpr::child_begin() { return &Val; }
1781Stmt::child_iterator VAArgExpr::child_end() { return &Val+1; }
Anders Carlsson36760332007-10-15 20:28:48 +00001782
Anders Carlsson762b7c72007-08-31 04:56:16 +00001783// InitListExpr
1784Stmt::child_iterator InitListExpr::child_begin() {
Ted Kremenek2719e982008-06-17 02:43:46 +00001785 return InitExprs.size() ? &InitExprs[0] : 0;
Anders Carlsson762b7c72007-08-31 04:56:16 +00001786}
1787Stmt::child_iterator InitListExpr::child_end() {
Ted Kremenek2719e982008-06-17 02:43:46 +00001788 return InitExprs.size() ? &InitExprs[0] + InitExprs.size() : 0;
Anders Carlsson762b7c72007-08-31 04:56:16 +00001789}
1790
Douglas Gregorc9e012a2009-01-29 17:44:32 +00001791// DesignatedInitExpr
Douglas Gregorc5a6bdc2009-01-22 00:58:24 +00001792Stmt::child_iterator DesignatedInitExpr::child_begin() {
1793 char* Ptr = static_cast<char*>(static_cast<void *>(this));
1794 Ptr += sizeof(DesignatedInitExpr);
1795 Ptr += sizeof(Designator) * NumDesignators;
1796 return reinterpret_cast<Stmt**>(reinterpret_cast<void**>(Ptr));
1797}
1798Stmt::child_iterator DesignatedInitExpr::child_end() {
1799 return child_iterator(&*child_begin() + NumSubExprs);
1800}
1801
Douglas Gregorc9e012a2009-01-29 17:44:32 +00001802// ImplicitValueInitExpr
1803Stmt::child_iterator ImplicitValueInitExpr::child_begin() {
1804 return child_iterator();
1805}
1806
1807Stmt::child_iterator ImplicitValueInitExpr::child_end() {
1808 return child_iterator();
1809}
1810
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001811// ObjCStringLiteral
Ted Kremeneka6478552007-10-18 23:28:49 +00001812Stmt::child_iterator ObjCStringLiteral::child_begin() {
1813 return child_iterator();
1814}
1815Stmt::child_iterator ObjCStringLiteral::child_end() {
1816 return child_iterator();
1817}
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001818
1819// ObjCEncodeExpr
Ted Kremeneka6478552007-10-18 23:28:49 +00001820Stmt::child_iterator ObjCEncodeExpr::child_begin() { return child_iterator(); }
1821Stmt::child_iterator ObjCEncodeExpr::child_end() { return child_iterator(); }
Ted Kremenek9fdc8a92007-08-24 20:06:47 +00001822
Fariborz Jahanianf807c202007-10-16 20:40:23 +00001823// ObjCSelectorExpr
Ted Kremeneka6478552007-10-18 23:28:49 +00001824Stmt::child_iterator ObjCSelectorExpr::child_begin() {
1825 return child_iterator();
1826}
1827Stmt::child_iterator ObjCSelectorExpr::child_end() {
1828 return child_iterator();
1829}
Fariborz Jahanianf807c202007-10-16 20:40:23 +00001830
Fariborz Jahanianb391e6e2007-10-17 16:58:11 +00001831// ObjCProtocolExpr
Ted Kremeneka6478552007-10-18 23:28:49 +00001832Stmt::child_iterator ObjCProtocolExpr::child_begin() {
1833 return child_iterator();
1834}
1835Stmt::child_iterator ObjCProtocolExpr::child_end() {
1836 return child_iterator();
1837}
Fariborz Jahanianb391e6e2007-10-17 16:58:11 +00001838
Steve Naroffc39ca262007-09-18 23:55:05 +00001839// ObjCMessageExpr
Ted Kremenekd029a6f2008-05-01 17:26:20 +00001840Stmt::child_iterator ObjCMessageExpr::child_begin() {
Ted Kremenek2719e982008-06-17 02:43:46 +00001841 return getReceiver() ? &SubExprs[0] : &SubExprs[0] + ARGS_START;
Steve Naroffc39ca262007-09-18 23:55:05 +00001842}
1843Stmt::child_iterator ObjCMessageExpr::child_end() {
Ted Kremenek2719e982008-06-17 02:43:46 +00001844 return &SubExprs[0]+ARGS_START+getNumArgs();
Steve Naroffc39ca262007-09-18 23:55:05 +00001845}
1846
Steve Naroff52a81c02008-09-03 18:15:37 +00001847// Blocks
Steve Naroff9ac456d2008-10-08 17:01:13 +00001848Stmt::child_iterator BlockExpr::child_begin() { return child_iterator(); }
1849Stmt::child_iterator BlockExpr::child_end() { return child_iterator(); }
Steve Naroff52a81c02008-09-03 18:15:37 +00001850
Ted Kremenek4a1f5de2008-09-26 23:24:14 +00001851Stmt::child_iterator BlockDeclRefExpr::child_begin() { return child_iterator();}
1852Stmt::child_iterator BlockDeclRefExpr::child_end() { return child_iterator(); }