blob: 6af20df4bebac15bb577ce526f0839fea5a2b671 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- Stmt.cpp - Statement AST Node Implementation ---------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Stmt class and statement subclasses.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/AST/Stmt.h"
15#include "clang/AST/ExprCXX.h"
Steve Narofff494b572008-05-29 21:12:08 +000016#include "clang/AST/ExprObjC.h"
Chris Lattner16f00492009-04-26 01:32:48 +000017#include "clang/AST/StmtCXX.h"
18#include "clang/AST/StmtObjC.h"
Sebastian Redl4b07b292008-12-22 19:15:10 +000019#include "clang/AST/Type.h"
Ted Kremenek11e5a7f2009-02-06 01:42:09 +000020#include "clang/AST/ASTContext.h"
Chris Lattner3182db12009-03-10 23:51:40 +000021#include "clang/AST/ASTDiagnostic.h"
Chris Lattner9bffb072010-04-23 16:29:58 +000022#include "clang/Basic/TargetInfo.h"
Chandler Carruthb43c8ec2011-07-04 06:13:27 +000023#include "llvm/Support/raw_ostream.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000024using namespace clang;
25
Reid Spencer5f016e22007-07-11 17:01:13 +000026static struct StmtClassNameTable {
Chris Lattner63381352007-08-25 01:42:24 +000027 const char *Name;
28 unsigned Counter;
29 unsigned Size;
Sean Hunt4bfe1962010-05-05 15:24:00 +000030} StmtClassInfo[Stmt::lastStmtConstant+1];
Chris Lattner63381352007-08-25 01:42:24 +000031
32static StmtClassNameTable &getStmtInfoTableEntry(Stmt::StmtClass E) {
33 static bool Initialized = false;
34 if (Initialized)
35 return StmtClassInfo[E];
36
37 // Intialize the table on the first use.
38 Initialized = true;
Sean Hunt7381d5c2010-05-18 06:22:21 +000039#define ABSTRACT_STMT(STMT)
Douglas Gregorf2cad862008-11-14 12:46:07 +000040#define STMT(CLASS, PARENT) \
41 StmtClassInfo[(unsigned)Stmt::CLASS##Class].Name = #CLASS; \
42 StmtClassInfo[(unsigned)Stmt::CLASS##Class].Size = sizeof(CLASS);
Sean Hunt4bfe1962010-05-05 15:24:00 +000043#include "clang/AST/StmtNodes.inc"
Nico Weber608b17f2008-08-05 23:15:29 +000044
Chris Lattner63381352007-08-25 01:42:24 +000045 return StmtClassInfo[E];
46}
47
Reid Spencer5f016e22007-07-11 17:01:13 +000048const char *Stmt::getStmtClassName() const {
John McCall8e6285a2010-10-26 08:39:16 +000049 return getStmtInfoTableEntry((StmtClass) StmtBits.sClass).Name;
Reid Spencer5f016e22007-07-11 17:01:13 +000050}
51
52void Stmt::PrintStats() {
Chris Lattner63381352007-08-25 01:42:24 +000053 // Ensure the table is primed.
54 getStmtInfoTableEntry(Stmt::NullStmtClass);
Nico Weber608b17f2008-08-05 23:15:29 +000055
Reid Spencer5f016e22007-07-11 17:01:13 +000056 unsigned sum = 0;
Chandler Carruthb43c8ec2011-07-04 06:13:27 +000057 llvm::errs() << "\n*** Stmt/Expr Stats:\n";
Sean Hunt4bfe1962010-05-05 15:24:00 +000058 for (int i = 0; i != Stmt::lastStmtConstant+1; i++) {
Chris Lattner63381352007-08-25 01:42:24 +000059 if (StmtClassInfo[i].Name == 0) continue;
60 sum += StmtClassInfo[i].Counter;
Reid Spencer5f016e22007-07-11 17:01:13 +000061 }
Chandler Carruthb43c8ec2011-07-04 06:13:27 +000062 llvm::errs() << " " << sum << " stmts/exprs total.\n";
Reid Spencer5f016e22007-07-11 17:01:13 +000063 sum = 0;
Sean Hunt4bfe1962010-05-05 15:24:00 +000064 for (int i = 0; i != Stmt::lastStmtConstant+1; i++) {
Chris Lattner63381352007-08-25 01:42:24 +000065 if (StmtClassInfo[i].Name == 0) continue;
Douglas Gregordbe833d2009-05-26 14:40:08 +000066 if (StmtClassInfo[i].Counter == 0) continue;
Chandler Carruthb43c8ec2011-07-04 06:13:27 +000067 llvm::errs() << " " << StmtClassInfo[i].Counter << " "
68 << StmtClassInfo[i].Name << ", " << StmtClassInfo[i].Size
69 << " each (" << StmtClassInfo[i].Counter*StmtClassInfo[i].Size
70 << " bytes)\n";
Chris Lattner63381352007-08-25 01:42:24 +000071 sum += StmtClassInfo[i].Counter*StmtClassInfo[i].Size;
Reid Spencer5f016e22007-07-11 17:01:13 +000072 }
Chandler Carruthb43c8ec2011-07-04 06:13:27 +000073
74 llvm::errs() << "Total bytes = " << sum << "\n";
Reid Spencer5f016e22007-07-11 17:01:13 +000075}
76
77void Stmt::addStmtClass(StmtClass s) {
Chris Lattner63381352007-08-25 01:42:24 +000078 ++getStmtInfoTableEntry(s).Counter;
Reid Spencer5f016e22007-07-11 17:01:13 +000079}
80
Daniel Dunbar02892a62012-03-05 21:42:49 +000081bool Stmt::StatisticsEnabled = false;
82void Stmt::EnableStatistics() {
83 StatisticsEnabled = true;
Reid Spencer5f016e22007-07-11 17:01:13 +000084}
85
John McCall7e5e5f42011-07-07 06:58:02 +000086Stmt *Stmt::IgnoreImplicit() {
87 Stmt *s = this;
88
89 if (ExprWithCleanups *ewc = dyn_cast<ExprWithCleanups>(s))
90 s = ewc->getSubExpr();
91
92 while (ImplicitCastExpr *ice = dyn_cast<ImplicitCastExpr>(s))
93 s = ice->getSubExpr();
94
95 return s;
96}
97
Chandler Carrutha1364be2011-09-10 00:02:34 +000098/// \brief Strip off all label-like statements.
99///
100/// This will strip off label statements, case statements, and default
101/// statements recursively.
102const Stmt *Stmt::stripLabelLikeStatements() const {
103 const Stmt *S = this;
104 while (true) {
105 if (const LabelStmt *LS = dyn_cast<LabelStmt>(S))
106 S = LS->getSubStmt();
107 else if (const SwitchCase *SC = dyn_cast<SwitchCase>(S))
108 S = SC->getSubStmt();
109 else
110 return S;
111 }
112}
113
John McCall63c00d72011-02-09 08:16:59 +0000114namespace {
115 struct good {};
116 struct bad {};
John McCallf8c7fdb2011-02-09 08:31:17 +0000117
118 // These silly little functions have to be static inline to suppress
119 // unused warnings, and they have to be defined to suppress other
120 // warnings.
Nick Lewycky086eb9f2011-02-09 08:42:57 +0000121 static inline good is_good(good) { return good(); }
John McCall63c00d72011-02-09 08:16:59 +0000122
123 typedef Stmt::child_range children_t();
Nick Lewycky086eb9f2011-02-09 08:42:57 +0000124 template <class T> good implements_children(children_t T::*) {
125 return good();
126 }
127 static inline bad implements_children(children_t Stmt::*) {
128 return bad();
129 }
John McCall63c00d72011-02-09 08:16:59 +0000130
131 typedef SourceRange getSourceRange_t() const;
Nick Lewycky086eb9f2011-02-09 08:42:57 +0000132 template <class T> good implements_getSourceRange(getSourceRange_t T::*) {
133 return good();
134 }
135 static inline bad implements_getSourceRange(getSourceRange_t Stmt::*) {
136 return bad();
137 }
John McCall63c00d72011-02-09 08:16:59 +0000138
139#define ASSERT_IMPLEMENTS_children(type) \
140 (void) sizeof(is_good(implements_children(&type::children)))
141#define ASSERT_IMPLEMENTS_getSourceRange(type) \
142 (void) sizeof(is_good(implements_getSourceRange(&type::getSourceRange)))
143}
144
145/// Check whether the various Stmt classes implement their member
146/// functions.
147static inline void check_implementations() {
148#define ABSTRACT_STMT(type)
149#define STMT(type, base) \
150 ASSERT_IMPLEMENTS_children(type); \
151 ASSERT_IMPLEMENTS_getSourceRange(type);
152#include "clang/AST/StmtNodes.inc"
153}
154
155Stmt::child_range Stmt::children() {
156 switch (getStmtClass()) {
157 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
158#define ABSTRACT_STMT(type)
159#define STMT(type, base) \
160 case Stmt::type##Class: \
161 return static_cast<type*>(this)->children();
162#include "clang/AST/StmtNodes.inc"
163 }
164 llvm_unreachable("unknown statement kind!");
John McCall63c00d72011-02-09 08:16:59 +0000165}
166
167SourceRange Stmt::getSourceRange() const {
168 switch (getStmtClass()) {
169 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
170#define ABSTRACT_STMT(type)
171#define STMT(type, base) \
172 case Stmt::type##Class: \
173 return static_cast<const type*>(this)->getSourceRange();
174#include "clang/AST/StmtNodes.inc"
175 }
176 llvm_unreachable("unknown statement kind!");
John McCall63c00d72011-02-09 08:16:59 +0000177}
178
Daniel Dunbar90e25a82012-03-09 15:39:19 +0000179// Amusing macro metaprogramming hack: check whether a class provides
180// a more specific implementation of getLocStart() and getLocEnd().
181//
182// See also Expr.cpp:getExprLoc().
183namespace {
184 /// This implementation is used when a class provides a custom
185 /// implementation of getLocStart.
186 template <class S, class T>
187 SourceLocation getLocStartImpl(const Stmt *stmt,
188 SourceLocation (T::*v)() const) {
189 return static_cast<const S*>(stmt)->getLocStart();
190 }
191
192 /// This implementation is used when a class doesn't provide a custom
193 /// implementation of getLocStart. Overload resolution should pick it over
194 /// the implementation above because it's more specialized according to
195 /// function template partial ordering.
196 template <class S>
197 SourceLocation getLocStartImpl(const Stmt *stmt,
198 SourceLocation (Stmt::*v)() const) {
199 return static_cast<const S*>(stmt)->getSourceRange().getBegin();
200 }
201
202 /// This implementation is used when a class provides a custom
203 /// implementation of getLocEnd.
204 template <class S, class T>
205 SourceLocation getLocEndImpl(const Stmt *stmt,
206 SourceLocation (T::*v)() const) {
207 return static_cast<const S*>(stmt)->getLocEnd();
208 }
209
210 /// This implementation is used when a class doesn't provide a custom
211 /// implementation of getLocEnd. Overload resolution should pick it over
212 /// the implementation above because it's more specialized according to
213 /// function template partial ordering.
214 template <class S>
215 SourceLocation getLocEndImpl(const Stmt *stmt,
216 SourceLocation (Stmt::*v)() const) {
217 return static_cast<const S*>(stmt)->getSourceRange().getEnd();
218 }
219}
220
221SourceLocation Stmt::getLocStart() const {
222 switch (getStmtClass()) {
223 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
224#define ABSTRACT_STMT(type)
225#define STMT(type, base) \
226 case Stmt::type##Class: \
227 return getLocStartImpl<type>(this, &type::getLocStart);
228#include "clang/AST/StmtNodes.inc"
229 }
230 llvm_unreachable("unknown statement kind");
231}
232
233SourceLocation Stmt::getLocEnd() const {
234 switch (getStmtClass()) {
235 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
236#define ABSTRACT_STMT(type)
237#define STMT(type, base) \
238 case Stmt::type##Class: \
239 return getLocEndImpl<type>(this, &type::getLocEnd);
240#include "clang/AST/StmtNodes.inc"
241 }
242 llvm_unreachable("unknown statement kind");
243}
244
Douglas Gregor025452f2009-04-17 00:04:06 +0000245void CompoundStmt::setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts) {
246 if (this->Body)
247 C.Deallocate(Body);
John McCall8e6285a2010-10-26 08:39:16 +0000248 this->CompoundStmtBits.NumStmts = NumStmts;
Douglas Gregor025452f2009-04-17 00:04:06 +0000249
250 Body = new (C) Stmt*[NumStmts];
251 memcpy(Body, Stmts, sizeof(Stmt *) * NumStmts);
252}
Reid Spencer5f016e22007-07-11 17:01:13 +0000253
Reid Spencer5f016e22007-07-11 17:01:13 +0000254const char *LabelStmt::getName() const {
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000255 return getDecl()->getIdentifier()->getNameStart();
Reid Spencer5f016e22007-07-11 17:01:13 +0000256}
257
Steve Naroff507f2d52007-08-31 23:49:30 +0000258// This is defined here to avoid polluting Stmt.h with importing Expr.h
Nico Weber608b17f2008-08-05 23:15:29 +0000259SourceRange ReturnStmt::getSourceRange() const {
Steve Naroff507f2d52007-08-31 23:49:30 +0000260 if (RetExpr)
261 return SourceRange(RetLoc, RetExpr->getLocEnd());
262 else
263 return SourceRange(RetLoc);
264}
265
Ted Kremenekd48ade62007-10-01 16:34:52 +0000266bool Stmt::hasImplicitControlFlow() const {
John McCall8e6285a2010-10-26 08:39:16 +0000267 switch (StmtBits.sClass) {
Ted Kremenekd48ade62007-10-01 16:34:52 +0000268 default:
269 return false;
Nico Weber608b17f2008-08-05 23:15:29 +0000270
Ted Kremenekd48ade62007-10-01 16:34:52 +0000271 case CallExprClass:
272 case ConditionalOperatorClass:
273 case ChooseExprClass:
274 case StmtExprClass:
275 case DeclStmtClass:
Nico Weber608b17f2008-08-05 23:15:29 +0000276 return true;
277
Ted Kremenekd48ade62007-10-01 16:34:52 +0000278 case Stmt::BinaryOperatorClass: {
279 const BinaryOperator* B = cast<BinaryOperator>(this);
John McCall2de56d12010-08-25 11:45:40 +0000280 if (B->isLogicalOp() || B->getOpcode() == BO_Comma)
Ted Kremenekd48ade62007-10-01 16:34:52 +0000281 return true;
282 else
283 return false;
284 }
285 }
286}
287
Chris Lattnerb3277932009-03-10 04:59:06 +0000288Expr *AsmStmt::getOutputExpr(unsigned i) {
Ted Kremenekce2fc3a2008-10-27 18:40:21 +0000289 return cast<Expr>(Exprs[i]);
290}
Chris Lattnerb3277932009-03-10 04:59:06 +0000291
292/// getOutputConstraint - Return the constraint string for the specified
293/// output operand. All output constraints are known to be non-empty (either
294/// '=' or '+').
Chris Lattner5f9e2722011-07-23 10:55:15 +0000295StringRef AsmStmt::getOutputConstraint(unsigned i) const {
Anders Carlssonacb6bcb2010-01-30 20:38:10 +0000296 return getOutputConstraintLiteral(i)->getString();
Ted Kremenekce2fc3a2008-10-27 18:40:21 +0000297}
Chris Lattnerb3277932009-03-10 04:59:06 +0000298
Chris Lattner85759272009-03-11 00:23:13 +0000299/// getNumPlusOperands - Return the number of output operands that have a "+"
300/// constraint.
301unsigned AsmStmt::getNumPlusOperands() const {
302 unsigned Res = 0;
303 for (unsigned i = 0, e = getNumOutputs(); i != e; ++i)
304 if (isOutputPlusConstraint(i))
305 ++Res;
306 return Res;
307}
308
Chris Lattnerb3277932009-03-10 04:59:06 +0000309Expr *AsmStmt::getInputExpr(unsigned i) {
Ted Kremenekce2fc3a2008-10-27 18:40:21 +0000310 return cast<Expr>(Exprs[i + NumOutputs]);
311}
Chris Lattner935f0f02011-02-21 22:09:29 +0000312void AsmStmt::setInputExpr(unsigned i, Expr *E) {
313 Exprs[i + NumOutputs] = E;
314}
315
Chris Lattnerb3277932009-03-10 04:59:06 +0000316
317/// getInputConstraint - Return the specified input constraint. Unlike output
318/// constraints, these can be empty.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000319StringRef AsmStmt::getInputConstraint(unsigned i) const {
Anders Carlssonacb6bcb2010-01-30 20:38:10 +0000320 return getInputConstraintLiteral(i)->getString();
Ted Kremenekce2fc3a2008-10-27 18:40:21 +0000321}
322
Chris Lattner10ca96a2009-03-10 06:33:24 +0000323
Anders Carlssonacb6bcb2010-01-30 20:38:10 +0000324void AsmStmt::setOutputsAndInputsAndClobbers(ASTContext &C,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000325 IdentifierInfo **Names,
Anders Carlssonfdba9c02010-01-30 19:34:25 +0000326 StringLiteral **Constraints,
327 Stmt **Exprs,
328 unsigned NumOutputs,
Sean Huntc3021132010-05-05 15:23:54 +0000329 unsigned NumInputs,
Anders Carlssonfdba9c02010-01-30 19:34:25 +0000330 StringLiteral **Clobbers,
331 unsigned NumClobbers) {
Douglas Gregorcd7d5a92009-04-17 20:57:14 +0000332 this->NumOutputs = NumOutputs;
333 this->NumInputs = NumInputs;
Anders Carlsson966146e2010-01-30 23:19:41 +0000334 this->NumClobbers = NumClobbers;
335
336 unsigned NumExprs = NumOutputs + NumInputs;
Sean Huntc3021132010-05-05 15:23:54 +0000337
Anders Carlsson966146e2010-01-30 23:19:41 +0000338 C.Deallocate(this->Names);
339 this->Names = new (C) IdentifierInfo*[NumExprs];
340 std::copy(Names, Names + NumExprs, this->Names);
Sean Huntc3021132010-05-05 15:23:54 +0000341
Anders Carlsson966146e2010-01-30 23:19:41 +0000342 C.Deallocate(this->Exprs);
343 this->Exprs = new (C) Stmt*[NumExprs];
344 std::copy(Exprs, Exprs + NumExprs, this->Exprs);
Sean Huntc3021132010-05-05 15:23:54 +0000345
Anders Carlsson966146e2010-01-30 23:19:41 +0000346 C.Deallocate(this->Constraints);
347 this->Constraints = new (C) StringLiteral*[NumExprs];
348 std::copy(Constraints, Constraints + NumExprs, this->Constraints);
Sean Huntc3021132010-05-05 15:23:54 +0000349
Anders Carlsson966146e2010-01-30 23:19:41 +0000350 C.Deallocate(this->Clobbers);
351 this->Clobbers = new (C) StringLiteral*[NumClobbers];
352 std::copy(Clobbers, Clobbers + NumClobbers, this->Clobbers);
Douglas Gregorcd7d5a92009-04-17 20:57:14 +0000353}
354
Chris Lattner10ca96a2009-03-10 06:33:24 +0000355/// getNamedOperand - Given a symbolic operand reference like %[foo],
356/// translate this into a numeric value needed to reference the same operand.
357/// This returns -1 if the operand name is invalid.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000358int AsmStmt::getNamedOperand(StringRef SymbolicName) const {
Chris Lattner10ca96a2009-03-10 06:33:24 +0000359 unsigned NumPlusOperands = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000360
Chris Lattner10ca96a2009-03-10 06:33:24 +0000361 // Check if this is an output operand.
362 for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) {
363 if (getOutputName(i) == SymbolicName)
364 return i;
Chris Lattner10ca96a2009-03-10 06:33:24 +0000365 }
Mike Stump1eb44332009-09-09 15:08:12 +0000366
Chris Lattner10ca96a2009-03-10 06:33:24 +0000367 for (unsigned i = 0, e = getNumInputs(); i != e; ++i)
368 if (getInputName(i) == SymbolicName)
369 return getNumOutputs() + NumPlusOperands + i;
370
371 // Not found.
372 return -1;
373}
374
Chris Lattner458cd9c2009-03-10 23:21:44 +0000375/// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
376/// it into pieces. If the asm string is erroneous, emit errors and return
377/// true, otherwise return false.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000378unsigned AsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces,
Chris Lattnerfb5058e2009-03-10 23:41:04 +0000379 ASTContext &C, unsigned &DiagOffs) const {
Chris Lattner5f9e2722011-07-23 10:55:15 +0000380 StringRef Str = getAsmString()->getString();
Benjamin Kramer2f4eaef2010-08-17 12:54:38 +0000381 const char *StrStart = Str.begin();
382 const char *StrEnd = Str.end();
Chris Lattner3182db12009-03-10 23:51:40 +0000383 const char *CurPtr = StrStart;
Mike Stump1eb44332009-09-09 15:08:12 +0000384
Chris Lattner458cd9c2009-03-10 23:21:44 +0000385 // "Simple" inline asms have no constraints or operands, just convert the asm
386 // string to escape $'s.
387 if (isSimple()) {
388 std::string Result;
Chris Lattner3182db12009-03-10 23:51:40 +0000389 for (; CurPtr != StrEnd; ++CurPtr) {
390 switch (*CurPtr) {
Chris Lattner458cd9c2009-03-10 23:21:44 +0000391 case '$':
392 Result += "$$";
393 break;
394 default:
Chris Lattner3182db12009-03-10 23:51:40 +0000395 Result += *CurPtr;
Chris Lattner458cd9c2009-03-10 23:21:44 +0000396 break;
397 }
398 }
399 Pieces.push_back(AsmStringPiece(Result));
Chris Lattner3182db12009-03-10 23:51:40 +0000400 return 0;
Chris Lattner458cd9c2009-03-10 23:21:44 +0000401 }
402
403 // CurStringPiece - The current string that we are building up as we scan the
404 // asm string.
405 std::string CurStringPiece;
Mike Stump1eb44332009-09-09 15:08:12 +0000406
Douglas Gregorbcfd1f52011-09-02 00:18:52 +0000407 bool HasVariants = !C.getTargetInfo().hasNoAsmVariants();
Sean Huntc3021132010-05-05 15:23:54 +0000408
Chris Lattner458cd9c2009-03-10 23:21:44 +0000409 while (1) {
410 // Done with the string?
Chris Lattner3182db12009-03-10 23:51:40 +0000411 if (CurPtr == StrEnd) {
Chris Lattner458cd9c2009-03-10 23:21:44 +0000412 if (!CurStringPiece.empty())
413 Pieces.push_back(AsmStringPiece(CurStringPiece));
Chris Lattner3182db12009-03-10 23:51:40 +0000414 return 0;
Chris Lattner458cd9c2009-03-10 23:21:44 +0000415 }
Mike Stump1eb44332009-09-09 15:08:12 +0000416
Chris Lattner3182db12009-03-10 23:51:40 +0000417 char CurChar = *CurPtr++;
Chris Lattner018b54e2010-04-05 18:44:00 +0000418 switch (CurChar) {
419 case '$': CurStringPiece += "$$"; continue;
Chris Lattner9bffb072010-04-23 16:29:58 +0000420 case '{': CurStringPiece += (HasVariants ? "$(" : "{"); continue;
421 case '|': CurStringPiece += (HasVariants ? "$|" : "|"); continue;
422 case '}': CurStringPiece += (HasVariants ? "$)" : "}"); continue;
Chris Lattner018b54e2010-04-05 18:44:00 +0000423 case '%':
424 break;
425 default:
Chris Lattner458cd9c2009-03-10 23:21:44 +0000426 CurStringPiece += CurChar;
427 continue;
428 }
Sean Huntc3021132010-05-05 15:23:54 +0000429
Chris Lattner458cd9c2009-03-10 23:21:44 +0000430 // Escaped "%" character in asm string.
Chris Lattnereab8cfb2009-03-11 00:06:36 +0000431 if (CurPtr == StrEnd) {
432 // % at end of string is invalid (no escape).
433 DiagOffs = CurPtr-StrStart-1;
434 return diag::err_asm_invalid_escape;
435 }
Mike Stump1eb44332009-09-09 15:08:12 +0000436
Chris Lattner3182db12009-03-10 23:51:40 +0000437 char EscapedChar = *CurPtr++;
Chris Lattner458cd9c2009-03-10 23:21:44 +0000438 if (EscapedChar == '%') { // %% -> %
439 // Escaped percentage sign.
440 CurStringPiece += '%';
441 continue;
442 }
Mike Stump1eb44332009-09-09 15:08:12 +0000443
Chris Lattner458cd9c2009-03-10 23:21:44 +0000444 if (EscapedChar == '=') { // %= -> Generate an unique ID.
445 CurStringPiece += "${:uid}";
446 continue;
447 }
Mike Stump1eb44332009-09-09 15:08:12 +0000448
Chris Lattner458cd9c2009-03-10 23:21:44 +0000449 // Otherwise, we have an operand. If we have accumulated a string so far,
450 // add it to the Pieces list.
451 if (!CurStringPiece.empty()) {
452 Pieces.push_back(AsmStringPiece(CurStringPiece));
453 CurStringPiece.clear();
454 }
Mike Stump1eb44332009-09-09 15:08:12 +0000455
Chris Lattner458cd9c2009-03-10 23:21:44 +0000456 // Handle %x4 and %x[foo] by capturing x as the modifier character.
457 char Modifier = '\0';
458 if (isalpha(EscapedChar)) {
Benjamin Kramerbc57f3c2011-07-05 11:13:37 +0000459 if (CurPtr == StrEnd) { // Premature end.
460 DiagOffs = CurPtr-StrStart-1;
461 return diag::err_asm_invalid_escape;
462 }
Chris Lattner458cd9c2009-03-10 23:21:44 +0000463 Modifier = EscapedChar;
Chris Lattner3182db12009-03-10 23:51:40 +0000464 EscapedChar = *CurPtr++;
Chris Lattner458cd9c2009-03-10 23:21:44 +0000465 }
Mike Stump1eb44332009-09-09 15:08:12 +0000466
Chris Lattner458cd9c2009-03-10 23:21:44 +0000467 if (isdigit(EscapedChar)) {
468 // %n - Assembler operand n
Chris Lattnercafc2222009-03-11 22:52:17 +0000469 unsigned N = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000470
Chris Lattnercafc2222009-03-11 22:52:17 +0000471 --CurPtr;
472 while (CurPtr != StrEnd && isdigit(*CurPtr))
Chris Lattner32a47ed2009-03-11 23:09:16 +0000473 N = N*10 + ((*CurPtr++)-'0');
Mike Stump1eb44332009-09-09 15:08:12 +0000474
Chris Lattner85759272009-03-11 00:23:13 +0000475 unsigned NumOperands =
476 getNumOutputs() + getNumPlusOperands() + getNumInputs();
477 if (N >= NumOperands) {
478 DiagOffs = CurPtr-StrStart-1;
479 return diag::err_asm_invalid_operand_number;
480 }
481
Chris Lattner458cd9c2009-03-10 23:21:44 +0000482 Pieces.push_back(AsmStringPiece(N, Modifier));
483 continue;
484 }
Mike Stump1eb44332009-09-09 15:08:12 +0000485
Chris Lattner458cd9c2009-03-10 23:21:44 +0000486 // Handle %[foo], a symbolic operand reference.
487 if (EscapedChar == '[') {
Chris Lattnereab8cfb2009-03-11 00:06:36 +0000488 DiagOffs = CurPtr-StrStart-1;
Mike Stump1eb44332009-09-09 15:08:12 +0000489
Chris Lattnereab8cfb2009-03-11 00:06:36 +0000490 // Find the ']'.
Chris Lattner3182db12009-03-10 23:51:40 +0000491 const char *NameEnd = (const char*)memchr(CurPtr, ']', StrEnd-CurPtr);
Chris Lattnereab8cfb2009-03-11 00:06:36 +0000492 if (NameEnd == 0)
493 return diag::err_asm_unterminated_symbolic_operand_name;
494 if (NameEnd == CurPtr)
495 return diag::err_asm_empty_symbolic_operand_name;
Mike Stump1eb44332009-09-09 15:08:12 +0000496
Chris Lattner5f9e2722011-07-23 10:55:15 +0000497 StringRef SymbolicName(CurPtr, NameEnd - CurPtr);
Mike Stump1eb44332009-09-09 15:08:12 +0000498
Chris Lattner458cd9c2009-03-10 23:21:44 +0000499 int N = getNamedOperand(SymbolicName);
Chris Lattnereab8cfb2009-03-11 00:06:36 +0000500 if (N == -1) {
501 // Verify that an operand with that name exists.
502 DiagOffs = CurPtr-StrStart;
503 return diag::err_asm_unknown_symbolic_operand_name;
504 }
Chris Lattner458cd9c2009-03-10 23:21:44 +0000505 Pieces.push_back(AsmStringPiece(N, Modifier));
Mike Stump1eb44332009-09-09 15:08:12 +0000506
Chris Lattnereab8cfb2009-03-11 00:06:36 +0000507 CurPtr = NameEnd+1;
Chris Lattner458cd9c2009-03-10 23:21:44 +0000508 continue;
509 }
Mike Stump1eb44332009-09-09 15:08:12 +0000510
Chris Lattner2ff0f422009-03-10 23:57:07 +0000511 DiagOffs = CurPtr-StrStart-1;
Chris Lattner3182db12009-03-10 23:51:40 +0000512 return diag::err_asm_invalid_escape;
Chris Lattner458cd9c2009-03-10 23:21:44 +0000513 }
514}
515
Sam Weinigb0e4cb62010-02-03 02:09:59 +0000516QualType CXXCatchStmt::getCaughtType() const {
517 if (ExceptionDecl)
518 return ExceptionDecl->getType();
519 return QualType();
520}
521
Chris Lattnerdb6ed172008-01-30 05:01:46 +0000522//===----------------------------------------------------------------------===//
523// Constructors
524//===----------------------------------------------------------------------===//
525
Sean Huntc3021132010-05-05 15:23:54 +0000526AsmStmt::AsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple,
527 bool isvolatile, bool msasm,
Anders Carlsson966146e2010-01-30 23:19:41 +0000528 unsigned numoutputs, unsigned numinputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000529 IdentifierInfo **names, StringLiteral **constraints,
Chris Lattnerdb6ed172008-01-30 05:01:46 +0000530 Expr **exprs, StringLiteral *asmstr, unsigned numclobbers,
531 StringLiteral **clobbers, SourceLocation rparenloc)
Anders Carlssonb235fc22007-11-22 01:36:19 +0000532 : Stmt(AsmStmtClass), AsmLoc(asmloc), RParenLoc(rparenloc), AsmStr(asmstr)
Mike Stump3b11fd32010-01-04 22:37:17 +0000533 , IsSimple(issimple), IsVolatile(isvolatile), MSAsm(msasm)
Anders Carlsson966146e2010-01-30 23:19:41 +0000534 , NumOutputs(numoutputs), NumInputs(numinputs), NumClobbers(numclobbers) {
Nico Weber608b17f2008-08-05 23:15:29 +0000535
Anders Carlsson966146e2010-01-30 23:19:41 +0000536 unsigned NumExprs = NumOutputs +NumInputs;
Sean Huntc3021132010-05-05 15:23:54 +0000537
Anders Carlsson966146e2010-01-30 23:19:41 +0000538 Names = new (C) IdentifierInfo*[NumExprs];
539 std::copy(names, names + NumExprs, Names);
540
541 Exprs = new (C) Stmt*[NumExprs];
542 std::copy(exprs, exprs + NumExprs, Exprs);
543
544 Constraints = new (C) StringLiteral*[NumExprs];
545 std::copy(constraints, constraints + NumExprs, Constraints);
546
547 Clobbers = new (C) StringLiteral*[NumClobbers];
548 std::copy(clobbers, clobbers + NumClobbers, Clobbers);
Anders Carlssonb235fc22007-11-22 01:36:19 +0000549}
550
Chris Lattnerdb6ed172008-01-30 05:01:46 +0000551ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect,
552 Stmt *Body, SourceLocation FCL,
Nico Weber608b17f2008-08-05 23:15:29 +0000553 SourceLocation RPL)
Chris Lattnerdb6ed172008-01-30 05:01:46 +0000554: Stmt(ObjCForCollectionStmtClass) {
555 SubExprs[ELEM] = Elem;
556 SubExprs[COLLECTION] = reinterpret_cast<Stmt*>(Collect);
557 SubExprs[BODY] = Body;
558 ForLoc = FCL;
559 RParenLoc = RPL;
560}
561
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000562ObjCAtTryStmt::ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt,
563 Stmt **CatchStmts, unsigned NumCatchStmts,
564 Stmt *atFinallyStmt)
565 : Stmt(ObjCAtTryStmtClass), AtTryLoc(atTryLoc),
566 NumCatchStmts(NumCatchStmts), HasFinally(atFinallyStmt != 0)
567{
568 Stmt **Stmts = getStmts();
569 Stmts[0] = atTryStmt;
570 for (unsigned I = 0; I != NumCatchStmts; ++I)
571 Stmts[I + 1] = CatchStmts[I];
Sean Huntc3021132010-05-05 15:23:54 +0000572
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000573 if (HasFinally)
574 Stmts[NumCatchStmts + 1] = atFinallyStmt;
575}
Chris Lattnerdb6ed172008-01-30 05:01:46 +0000576
Sean Huntc3021132010-05-05 15:23:54 +0000577ObjCAtTryStmt *ObjCAtTryStmt::Create(ASTContext &Context,
578 SourceLocation atTryLoc,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000579 Stmt *atTryStmt,
Sean Huntc3021132010-05-05 15:23:54 +0000580 Stmt **CatchStmts,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000581 unsigned NumCatchStmts,
582 Stmt *atFinallyStmt) {
Sean Huntc3021132010-05-05 15:23:54 +0000583 unsigned Size = sizeof(ObjCAtTryStmt) +
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000584 (1 + NumCatchStmts + (atFinallyStmt != 0)) * sizeof(Stmt *);
Chris Lattner32488542010-10-30 05:14:06 +0000585 void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>());
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000586 return new (Mem) ObjCAtTryStmt(atTryLoc, atTryStmt, CatchStmts, NumCatchStmts,
587 atFinallyStmt);
588}
Ted Kremenekff981022008-02-01 21:28:59 +0000589
Sean Huntc3021132010-05-05 15:23:54 +0000590ObjCAtTryStmt *ObjCAtTryStmt::CreateEmpty(ASTContext &Context,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000591 unsigned NumCatchStmts,
592 bool HasFinally) {
Sean Huntc3021132010-05-05 15:23:54 +0000593 unsigned Size = sizeof(ObjCAtTryStmt) +
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000594 (1 + NumCatchStmts + HasFinally) * sizeof(Stmt *);
Chris Lattner32488542010-10-30 05:14:06 +0000595 void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>());
Sean Huntc3021132010-05-05 15:23:54 +0000596 return new (Mem) ObjCAtTryStmt(EmptyShell(), NumCatchStmts, HasFinally);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000597}
Nico Weber608b17f2008-08-05 23:15:29 +0000598
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000599SourceRange ObjCAtTryStmt::getSourceRange() const {
600 SourceLocation EndLoc;
601 if (HasFinally)
602 EndLoc = getFinallyStmt()->getLocEnd();
603 else if (NumCatchStmts)
604 EndLoc = getCatchStmt(NumCatchStmts - 1)->getLocEnd();
605 else
606 EndLoc = getTryBody()->getLocEnd();
Sean Huntc3021132010-05-05 15:23:54 +0000607
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000608 return SourceRange(AtTryLoc, EndLoc);
Chris Lattnerdb6ed172008-01-30 05:01:46 +0000609}
610
Sam Weiniga1a396d2010-02-03 03:56:39 +0000611CXXTryStmt *CXXTryStmt::Create(ASTContext &C, SourceLocation tryLoc,
Sean Huntc3021132010-05-05 15:23:54 +0000612 Stmt *tryBlock, Stmt **handlers,
Sam Weiniga1a396d2010-02-03 03:56:39 +0000613 unsigned numHandlers) {
614 std::size_t Size = sizeof(CXXTryStmt);
615 Size += ((numHandlers + 1) * sizeof(Stmt));
616
Chris Lattner32488542010-10-30 05:14:06 +0000617 void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>());
Sam Weiniga1a396d2010-02-03 03:56:39 +0000618 return new (Mem) CXXTryStmt(tryLoc, tryBlock, handlers, numHandlers);
619}
620
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000621CXXTryStmt *CXXTryStmt::Create(ASTContext &C, EmptyShell Empty,
622 unsigned numHandlers) {
623 std::size_t Size = sizeof(CXXTryStmt);
624 Size += ((numHandlers + 1) * sizeof(Stmt));
625
Chris Lattner32488542010-10-30 05:14:06 +0000626 void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>());
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000627 return new (Mem) CXXTryStmt(Empty, numHandlers);
628}
629
Sam Weiniga1a396d2010-02-03 03:56:39 +0000630CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock,
Sam Weinigb0e4cb62010-02-03 02:09:59 +0000631 Stmt **handlers, unsigned numHandlers)
632 : Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(numHandlers) {
Sam Weiniga1a396d2010-02-03 03:56:39 +0000633 Stmt **Stmts = reinterpret_cast<Stmt **>(this + 1);
Sam Weinigb0e4cb62010-02-03 02:09:59 +0000634 Stmts[0] = tryBlock;
635 std::copy(handlers, handlers + NumHandlers, Stmts + 1);
636}
637
Richard Smithad762fc2011-04-14 22:09:26 +0000638CXXForRangeStmt::CXXForRangeStmt(DeclStmt *Range, DeclStmt *BeginEndStmt,
639 Expr *Cond, Expr *Inc, DeclStmt *LoopVar,
640 Stmt *Body, SourceLocation FL,
641 SourceLocation CL, SourceLocation RPL)
642 : Stmt(CXXForRangeStmtClass), ForLoc(FL), ColonLoc(CL), RParenLoc(RPL) {
643 SubExprs[RANGE] = Range;
644 SubExprs[BEGINEND] = BeginEndStmt;
645 SubExprs[COND] = reinterpret_cast<Stmt*>(Cond);
646 SubExprs[INC] = reinterpret_cast<Stmt*>(Inc);
647 SubExprs[LOOPVAR] = LoopVar;
648 SubExprs[BODY] = Body;
649}
650
651Expr *CXXForRangeStmt::getRangeInit() {
652 DeclStmt *RangeStmt = getRangeStmt();
653 VarDecl *RangeDecl = dyn_cast_or_null<VarDecl>(RangeStmt->getSingleDecl());
654 assert(RangeDecl &&& "for-range should have a single var decl");
655 return RangeDecl->getInit();
656}
657
658const Expr *CXXForRangeStmt::getRangeInit() const {
659 return const_cast<CXXForRangeStmt*>(this)->getRangeInit();
660}
661
662VarDecl *CXXForRangeStmt::getLoopVariable() {
663 Decl *LV = cast<DeclStmt>(getLoopVarStmt())->getSingleDecl();
664 assert(LV && "No loop variable in CXXForRangeStmt");
665 return cast<VarDecl>(LV);
666}
667
668const VarDecl *CXXForRangeStmt::getLoopVariable() const {
669 return const_cast<CXXForRangeStmt*>(this)->getLoopVariable();
670}
671
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000672IfStmt::IfStmt(ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +0000673 Stmt *then, SourceLocation EL, Stmt *elsev)
674 : Stmt(IfStmtClass), IfLoc(IL), ElseLoc(EL)
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000675{
676 setConditionVariable(C, var);
677 SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
678 SubExprs[THEN] = then;
679 SubExprs[ELSE] = elsev;
680}
681
682VarDecl *IfStmt::getConditionVariable() const {
683 if (!SubExprs[VAR])
684 return 0;
685
686 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
687 return cast<VarDecl>(DS->getSingleDecl());
688}
689
690void IfStmt::setConditionVariable(ASTContext &C, VarDecl *V) {
691 if (!V) {
692 SubExprs[VAR] = 0;
693 return;
694 }
695
Daniel Dunbar96a00142012-03-09 18:35:03 +0000696 SourceRange VarRange = V->getSourceRange();
697 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
698 VarRange.getEnd());
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000699}
700
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000701ForStmt::ForStmt(ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar,
702 Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP,
703 SourceLocation RP)
704 : Stmt(ForStmtClass), ForLoc(FL), LParenLoc(LP), RParenLoc(RP)
705{
706 SubExprs[INIT] = Init;
707 setConditionVariable(C, condVar);
708 SubExprs[COND] = reinterpret_cast<Stmt*>(Cond);
709 SubExprs[INC] = reinterpret_cast<Stmt*>(Inc);
710 SubExprs[BODY] = Body;
711}
712
713VarDecl *ForStmt::getConditionVariable() const {
714 if (!SubExprs[CONDVAR])
715 return 0;
716
717 DeclStmt *DS = cast<DeclStmt>(SubExprs[CONDVAR]);
718 return cast<VarDecl>(DS->getSingleDecl());
719}
720
721void ForStmt::setConditionVariable(ASTContext &C, VarDecl *V) {
722 if (!V) {
723 SubExprs[CONDVAR] = 0;
724 return;
725 }
726
Daniel Dunbar96a00142012-03-09 18:35:03 +0000727 SourceRange VarRange = V->getSourceRange();
728 SubExprs[CONDVAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
729 VarRange.getEnd());
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000730}
731
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000732SwitchStmt::SwitchStmt(ASTContext &C, VarDecl *Var, Expr *cond)
Ted Kremenek780d8852010-09-09 00:06:01 +0000733 : Stmt(SwitchStmtClass), FirstCase(0), AllEnumCasesCovered(0)
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000734{
735 setConditionVariable(C, Var);
736 SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
737 SubExprs[BODY] = NULL;
738}
739
740VarDecl *SwitchStmt::getConditionVariable() const {
741 if (!SubExprs[VAR])
742 return 0;
743
744 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
745 return cast<VarDecl>(DS->getSingleDecl());
746}
747
748void SwitchStmt::setConditionVariable(ASTContext &C, VarDecl *V) {
749 if (!V) {
750 SubExprs[VAR] = 0;
751 return;
752 }
753
Daniel Dunbar96a00142012-03-09 18:35:03 +0000754 SourceRange VarRange = V->getSourceRange();
755 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
756 VarRange.getEnd());
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000757}
758
John McCall63c00d72011-02-09 08:16:59 +0000759Stmt *SwitchCase::getSubStmt() {
Chris Lattnerc4002c72011-02-28 00:18:06 +0000760 if (isa<CaseStmt>(this))
761 return cast<CaseStmt>(this)->getSubStmt();
John McCall63c00d72011-02-09 08:16:59 +0000762 return cast<DefaultStmt>(this)->getSubStmt();
763}
764
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000765WhileStmt::WhileStmt(ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
766 SourceLocation WL)
Chris Lattnerc4002c72011-02-28 00:18:06 +0000767 : Stmt(WhileStmtClass) {
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000768 setConditionVariable(C, Var);
769 SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
770 SubExprs[BODY] = body;
771 WhileLoc = WL;
772}
773
774VarDecl *WhileStmt::getConditionVariable() const {
775 if (!SubExprs[VAR])
776 return 0;
777
778 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
779 return cast<VarDecl>(DS->getSingleDecl());
780}
781
782void WhileStmt::setConditionVariable(ASTContext &C, VarDecl *V) {
783 if (!V) {
784 SubExprs[VAR] = 0;
785 return;
786 }
Daniel Dunbar96a00142012-03-09 18:35:03 +0000787
788 SourceRange VarRange = V->getSourceRange();
789 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
790 VarRange.getEnd());
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000791}
792
Ted Kremenek82977772007-08-24 21:09:09 +0000793// IndirectGotoStmt
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000794LabelDecl *IndirectGotoStmt::getConstantTarget() {
John McCall95c225d2010-10-28 08:53:48 +0000795 if (AddrLabelExpr *E =
796 dyn_cast<AddrLabelExpr>(getTarget()->IgnoreParenImpCasts()))
797 return E->getLabel();
798 return 0;
799}
Ted Kremenek82977772007-08-24 21:09:09 +0000800
Ted Kremenek82977772007-08-24 21:09:09 +0000801// ReturnStmt
Ted Kremenek1060aff2008-06-17 03:11:08 +0000802const Expr* ReturnStmt::getRetValue() const {
803 return cast_or_null<Expr>(RetExpr);
804}
805Expr* ReturnStmt::getRetValue() {
806 return cast_or_null<Expr>(RetExpr);
Ted Kremenek82977772007-08-24 21:09:09 +0000807}
John Wiegley28bbe4b2011-04-28 01:08:34 +0000808
809SEHTryStmt::SEHTryStmt(bool IsCXXTry,
810 SourceLocation TryLoc,
811 Stmt *TryBlock,
812 Stmt *Handler)
813 : Stmt(SEHTryStmtClass),
814 IsCXXTry(IsCXXTry),
815 TryLoc(TryLoc)
816{
817 Children[TRY] = TryBlock;
818 Children[HANDLER] = Handler;
819}
820
821SEHTryStmt* SEHTryStmt::Create(ASTContext &C,
822 bool IsCXXTry,
823 SourceLocation TryLoc,
824 Stmt *TryBlock,
825 Stmt *Handler) {
826 return new(C) SEHTryStmt(IsCXXTry,TryLoc,TryBlock,Handler);
827}
828
829SEHExceptStmt* SEHTryStmt::getExceptHandler() const {
830 return dyn_cast<SEHExceptStmt>(getHandler());
831}
832
833SEHFinallyStmt* SEHTryStmt::getFinallyHandler() const {
834 return dyn_cast<SEHFinallyStmt>(getHandler());
835}
836
837SEHExceptStmt::SEHExceptStmt(SourceLocation Loc,
838 Expr *FilterExpr,
839 Stmt *Block)
840 : Stmt(SEHExceptStmtClass),
841 Loc(Loc)
842{
843 Children[FILTER_EXPR] = reinterpret_cast<Stmt*>(FilterExpr);
844 Children[BLOCK] = Block;
845}
846
847SEHExceptStmt* SEHExceptStmt::Create(ASTContext &C,
848 SourceLocation Loc,
849 Expr *FilterExpr,
850 Stmt *Block) {
851 return new(C) SEHExceptStmt(Loc,FilterExpr,Block);
852}
853
854SEHFinallyStmt::SEHFinallyStmt(SourceLocation Loc,
855 Stmt *Block)
856 : Stmt(SEHFinallyStmtClass),
857 Loc(Loc),
858 Block(Block)
859{}
860
861SEHFinallyStmt* SEHFinallyStmt::Create(ASTContext &C,
862 SourceLocation Loc,
863 Stmt *Block) {
864 return new(C)SEHFinallyStmt(Loc,Block);
865}