blob: e4d9f0a1ef425fd6595c1854754bd3ef1cfea65a [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///
Richard Smith534986f2012-04-14 00:33:13 +0000100/// This will strip off label statements, case statements, attributed
101/// statements and default statements recursively.
Chandler Carrutha1364be2011-09-10 00:02:34 +0000102const 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();
Richard Smith534986f2012-04-14 00:33:13 +0000109 else if (const AttributedStmt *AS = dyn_cast<AttributedStmt>(S))
110 S = AS->getSubStmt();
Chandler Carrutha1364be2011-09-10 00:02:34 +0000111 else
112 return S;
113 }
114}
115
John McCall63c00d72011-02-09 08:16:59 +0000116namespace {
117 struct good {};
118 struct bad {};
John McCallf8c7fdb2011-02-09 08:31:17 +0000119
120 // These silly little functions have to be static inline to suppress
121 // unused warnings, and they have to be defined to suppress other
122 // warnings.
Nick Lewycky086eb9f2011-02-09 08:42:57 +0000123 static inline good is_good(good) { return good(); }
John McCall63c00d72011-02-09 08:16:59 +0000124
125 typedef Stmt::child_range children_t();
Nick Lewycky086eb9f2011-02-09 08:42:57 +0000126 template <class T> good implements_children(children_t T::*) {
127 return good();
128 }
129 static inline bad implements_children(children_t Stmt::*) {
130 return bad();
131 }
John McCall63c00d72011-02-09 08:16:59 +0000132
133 typedef SourceRange getSourceRange_t() const;
Nick Lewycky086eb9f2011-02-09 08:42:57 +0000134 template <class T> good implements_getSourceRange(getSourceRange_t T::*) {
135 return good();
136 }
137 static inline bad implements_getSourceRange(getSourceRange_t Stmt::*) {
138 return bad();
139 }
John McCall63c00d72011-02-09 08:16:59 +0000140
141#define ASSERT_IMPLEMENTS_children(type) \
142 (void) sizeof(is_good(implements_children(&type::children)))
143#define ASSERT_IMPLEMENTS_getSourceRange(type) \
144 (void) sizeof(is_good(implements_getSourceRange(&type::getSourceRange)))
145}
146
147/// Check whether the various Stmt classes implement their member
148/// functions.
149static inline void check_implementations() {
150#define ABSTRACT_STMT(type)
151#define STMT(type, base) \
152 ASSERT_IMPLEMENTS_children(type); \
153 ASSERT_IMPLEMENTS_getSourceRange(type);
154#include "clang/AST/StmtNodes.inc"
155}
156
157Stmt::child_range Stmt::children() {
158 switch (getStmtClass()) {
159 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
160#define ABSTRACT_STMT(type)
161#define STMT(type, base) \
162 case Stmt::type##Class: \
163 return static_cast<type*>(this)->children();
164#include "clang/AST/StmtNodes.inc"
165 }
166 llvm_unreachable("unknown statement kind!");
John McCall63c00d72011-02-09 08:16:59 +0000167}
168
169SourceRange Stmt::getSourceRange() const {
170 switch (getStmtClass()) {
171 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
172#define ABSTRACT_STMT(type)
173#define STMT(type, base) \
174 case Stmt::type##Class: \
175 return static_cast<const type*>(this)->getSourceRange();
176#include "clang/AST/StmtNodes.inc"
177 }
178 llvm_unreachable("unknown statement kind!");
John McCall63c00d72011-02-09 08:16:59 +0000179}
180
Daniel Dunbar90e25a82012-03-09 15:39:19 +0000181// Amusing macro metaprogramming hack: check whether a class provides
182// a more specific implementation of getLocStart() and getLocEnd().
183//
184// See also Expr.cpp:getExprLoc().
185namespace {
186 /// This implementation is used when a class provides a custom
187 /// implementation of getLocStart.
188 template <class S, class T>
189 SourceLocation getLocStartImpl(const Stmt *stmt,
190 SourceLocation (T::*v)() const) {
191 return static_cast<const S*>(stmt)->getLocStart();
192 }
193
194 /// This implementation is used when a class doesn't provide a custom
195 /// implementation of getLocStart. Overload resolution should pick it over
196 /// the implementation above because it's more specialized according to
197 /// function template partial ordering.
198 template <class S>
199 SourceLocation getLocStartImpl(const Stmt *stmt,
200 SourceLocation (Stmt::*v)() const) {
201 return static_cast<const S*>(stmt)->getSourceRange().getBegin();
202 }
203
204 /// This implementation is used when a class provides a custom
205 /// implementation of getLocEnd.
206 template <class S, class T>
207 SourceLocation getLocEndImpl(const Stmt *stmt,
208 SourceLocation (T::*v)() const) {
209 return static_cast<const S*>(stmt)->getLocEnd();
210 }
211
212 /// This implementation is used when a class doesn't provide a custom
213 /// implementation of getLocEnd. Overload resolution should pick it over
214 /// the implementation above because it's more specialized according to
215 /// function template partial ordering.
216 template <class S>
217 SourceLocation getLocEndImpl(const Stmt *stmt,
218 SourceLocation (Stmt::*v)() const) {
219 return static_cast<const S*>(stmt)->getSourceRange().getEnd();
220 }
221}
222
223SourceLocation Stmt::getLocStart() const {
224 switch (getStmtClass()) {
225 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
226#define ABSTRACT_STMT(type)
227#define STMT(type, base) \
228 case Stmt::type##Class: \
229 return getLocStartImpl<type>(this, &type::getLocStart);
230#include "clang/AST/StmtNodes.inc"
231 }
232 llvm_unreachable("unknown statement kind");
233}
234
235SourceLocation Stmt::getLocEnd() const {
236 switch (getStmtClass()) {
237 case Stmt::NoStmtClass: llvm_unreachable("statement without class");
238#define ABSTRACT_STMT(type)
239#define STMT(type, base) \
240 case Stmt::type##Class: \
241 return getLocEndImpl<type>(this, &type::getLocEnd);
242#include "clang/AST/StmtNodes.inc"
243 }
244 llvm_unreachable("unknown statement kind");
245}
246
Douglas Gregor025452f2009-04-17 00:04:06 +0000247void CompoundStmt::setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts) {
248 if (this->Body)
249 C.Deallocate(Body);
John McCall8e6285a2010-10-26 08:39:16 +0000250 this->CompoundStmtBits.NumStmts = NumStmts;
Douglas Gregor025452f2009-04-17 00:04:06 +0000251
252 Body = new (C) Stmt*[NumStmts];
253 memcpy(Body, Stmts, sizeof(Stmt *) * NumStmts);
254}
Reid Spencer5f016e22007-07-11 17:01:13 +0000255
Reid Spencer5f016e22007-07-11 17:01:13 +0000256const char *LabelStmt::getName() const {
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000257 return getDecl()->getIdentifier()->getNameStart();
Reid Spencer5f016e22007-07-11 17:01:13 +0000258}
259
Steve Naroff507f2d52007-08-31 23:49:30 +0000260// This is defined here to avoid polluting Stmt.h with importing Expr.h
Nico Weber608b17f2008-08-05 23:15:29 +0000261SourceRange ReturnStmt::getSourceRange() const {
Steve Naroff507f2d52007-08-31 23:49:30 +0000262 if (RetExpr)
263 return SourceRange(RetLoc, RetExpr->getLocEnd());
264 else
265 return SourceRange(RetLoc);
266}
267
Ted Kremenekd48ade62007-10-01 16:34:52 +0000268bool Stmt::hasImplicitControlFlow() const {
John McCall8e6285a2010-10-26 08:39:16 +0000269 switch (StmtBits.sClass) {
Ted Kremenekd48ade62007-10-01 16:34:52 +0000270 default:
271 return false;
Nico Weber608b17f2008-08-05 23:15:29 +0000272
Ted Kremenekd48ade62007-10-01 16:34:52 +0000273 case CallExprClass:
274 case ConditionalOperatorClass:
275 case ChooseExprClass:
276 case StmtExprClass:
277 case DeclStmtClass:
Nico Weber608b17f2008-08-05 23:15:29 +0000278 return true;
279
Ted Kremenekd48ade62007-10-01 16:34:52 +0000280 case Stmt::BinaryOperatorClass: {
281 const BinaryOperator* B = cast<BinaryOperator>(this);
John McCall2de56d12010-08-25 11:45:40 +0000282 if (B->isLogicalOp() || B->getOpcode() == BO_Comma)
Ted Kremenekd48ade62007-10-01 16:34:52 +0000283 return true;
284 else
285 return false;
286 }
287 }
288}
289
Chris Lattnerb3277932009-03-10 04:59:06 +0000290Expr *AsmStmt::getOutputExpr(unsigned i) {
Ted Kremenekce2fc3a2008-10-27 18:40:21 +0000291 return cast<Expr>(Exprs[i]);
292}
Chris Lattnerb3277932009-03-10 04:59:06 +0000293
294/// getOutputConstraint - Return the constraint string for the specified
295/// output operand. All output constraints are known to be non-empty (either
296/// '=' or '+').
Chris Lattner5f9e2722011-07-23 10:55:15 +0000297StringRef AsmStmt::getOutputConstraint(unsigned i) const {
Anders Carlssonacb6bcb2010-01-30 20:38:10 +0000298 return getOutputConstraintLiteral(i)->getString();
Ted Kremenekce2fc3a2008-10-27 18:40:21 +0000299}
Chris Lattnerb3277932009-03-10 04:59:06 +0000300
Chris Lattner85759272009-03-11 00:23:13 +0000301/// getNumPlusOperands - Return the number of output operands that have a "+"
302/// constraint.
303unsigned AsmStmt::getNumPlusOperands() const {
304 unsigned Res = 0;
305 for (unsigned i = 0, e = getNumOutputs(); i != e; ++i)
306 if (isOutputPlusConstraint(i))
307 ++Res;
308 return Res;
309}
310
Chris Lattnerb3277932009-03-10 04:59:06 +0000311Expr *AsmStmt::getInputExpr(unsigned i) {
Ted Kremenekce2fc3a2008-10-27 18:40:21 +0000312 return cast<Expr>(Exprs[i + NumOutputs]);
313}
Chris Lattner935f0f02011-02-21 22:09:29 +0000314void AsmStmt::setInputExpr(unsigned i, Expr *E) {
315 Exprs[i + NumOutputs] = E;
316}
317
Chris Lattnerb3277932009-03-10 04:59:06 +0000318
319/// getInputConstraint - Return the specified input constraint. Unlike output
320/// constraints, these can be empty.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000321StringRef AsmStmt::getInputConstraint(unsigned i) const {
Anders Carlssonacb6bcb2010-01-30 20:38:10 +0000322 return getInputConstraintLiteral(i)->getString();
Ted Kremenekce2fc3a2008-10-27 18:40:21 +0000323}
324
Chris Lattner10ca96a2009-03-10 06:33:24 +0000325
Anders Carlssonacb6bcb2010-01-30 20:38:10 +0000326void AsmStmt::setOutputsAndInputsAndClobbers(ASTContext &C,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000327 IdentifierInfo **Names,
Anders Carlssonfdba9c02010-01-30 19:34:25 +0000328 StringLiteral **Constraints,
329 Stmt **Exprs,
330 unsigned NumOutputs,
Sean Huntc3021132010-05-05 15:23:54 +0000331 unsigned NumInputs,
Anders Carlssonfdba9c02010-01-30 19:34:25 +0000332 StringLiteral **Clobbers,
333 unsigned NumClobbers) {
Douglas Gregorcd7d5a92009-04-17 20:57:14 +0000334 this->NumOutputs = NumOutputs;
335 this->NumInputs = NumInputs;
Anders Carlsson966146e2010-01-30 23:19:41 +0000336 this->NumClobbers = NumClobbers;
337
338 unsigned NumExprs = NumOutputs + NumInputs;
Sean Huntc3021132010-05-05 15:23:54 +0000339
Anders Carlsson966146e2010-01-30 23:19:41 +0000340 C.Deallocate(this->Names);
341 this->Names = new (C) IdentifierInfo*[NumExprs];
342 std::copy(Names, Names + NumExprs, this->Names);
Sean Huntc3021132010-05-05 15:23:54 +0000343
Anders Carlsson966146e2010-01-30 23:19:41 +0000344 C.Deallocate(this->Exprs);
345 this->Exprs = new (C) Stmt*[NumExprs];
346 std::copy(Exprs, Exprs + NumExprs, this->Exprs);
Sean Huntc3021132010-05-05 15:23:54 +0000347
Anders Carlsson966146e2010-01-30 23:19:41 +0000348 C.Deallocate(this->Constraints);
349 this->Constraints = new (C) StringLiteral*[NumExprs];
350 std::copy(Constraints, Constraints + NumExprs, this->Constraints);
Sean Huntc3021132010-05-05 15:23:54 +0000351
Anders Carlsson966146e2010-01-30 23:19:41 +0000352 C.Deallocate(this->Clobbers);
353 this->Clobbers = new (C) StringLiteral*[NumClobbers];
354 std::copy(Clobbers, Clobbers + NumClobbers, this->Clobbers);
Douglas Gregorcd7d5a92009-04-17 20:57:14 +0000355}
356
Chris Lattner10ca96a2009-03-10 06:33:24 +0000357/// getNamedOperand - Given a symbolic operand reference like %[foo],
358/// translate this into a numeric value needed to reference the same operand.
359/// This returns -1 if the operand name is invalid.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000360int AsmStmt::getNamedOperand(StringRef SymbolicName) const {
Chris Lattner10ca96a2009-03-10 06:33:24 +0000361 unsigned NumPlusOperands = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000362
Chris Lattner10ca96a2009-03-10 06:33:24 +0000363 // Check if this is an output operand.
364 for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) {
365 if (getOutputName(i) == SymbolicName)
366 return i;
Chris Lattner10ca96a2009-03-10 06:33:24 +0000367 }
Mike Stump1eb44332009-09-09 15:08:12 +0000368
Chris Lattner10ca96a2009-03-10 06:33:24 +0000369 for (unsigned i = 0, e = getNumInputs(); i != e; ++i)
370 if (getInputName(i) == SymbolicName)
371 return getNumOutputs() + NumPlusOperands + i;
372
373 // Not found.
374 return -1;
375}
376
Chris Lattner458cd9c2009-03-10 23:21:44 +0000377/// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
378/// it into pieces. If the asm string is erroneous, emit errors and return
379/// true, otherwise return false.
Chris Lattner5f9e2722011-07-23 10:55:15 +0000380unsigned AsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces,
Chris Lattnerfb5058e2009-03-10 23:41:04 +0000381 ASTContext &C, unsigned &DiagOffs) const {
Chris Lattner5f9e2722011-07-23 10:55:15 +0000382 StringRef Str = getAsmString()->getString();
Benjamin Kramer2f4eaef2010-08-17 12:54:38 +0000383 const char *StrStart = Str.begin();
384 const char *StrEnd = Str.end();
Chris Lattner3182db12009-03-10 23:51:40 +0000385 const char *CurPtr = StrStart;
Mike Stump1eb44332009-09-09 15:08:12 +0000386
Chris Lattner458cd9c2009-03-10 23:21:44 +0000387 // "Simple" inline asms have no constraints or operands, just convert the asm
388 // string to escape $'s.
389 if (isSimple()) {
390 std::string Result;
Chris Lattner3182db12009-03-10 23:51:40 +0000391 for (; CurPtr != StrEnd; ++CurPtr) {
392 switch (*CurPtr) {
Chris Lattner458cd9c2009-03-10 23:21:44 +0000393 case '$':
394 Result += "$$";
395 break;
396 default:
Chris Lattner3182db12009-03-10 23:51:40 +0000397 Result += *CurPtr;
Chris Lattner458cd9c2009-03-10 23:21:44 +0000398 break;
399 }
400 }
401 Pieces.push_back(AsmStringPiece(Result));
Chris Lattner3182db12009-03-10 23:51:40 +0000402 return 0;
Chris Lattner458cd9c2009-03-10 23:21:44 +0000403 }
404
405 // CurStringPiece - The current string that we are building up as we scan the
406 // asm string.
407 std::string CurStringPiece;
Mike Stump1eb44332009-09-09 15:08:12 +0000408
Douglas Gregorbcfd1f52011-09-02 00:18:52 +0000409 bool HasVariants = !C.getTargetInfo().hasNoAsmVariants();
Sean Huntc3021132010-05-05 15:23:54 +0000410
Chris Lattner458cd9c2009-03-10 23:21:44 +0000411 while (1) {
412 // Done with the string?
Chris Lattner3182db12009-03-10 23:51:40 +0000413 if (CurPtr == StrEnd) {
Chris Lattner458cd9c2009-03-10 23:21:44 +0000414 if (!CurStringPiece.empty())
415 Pieces.push_back(AsmStringPiece(CurStringPiece));
Chris Lattner3182db12009-03-10 23:51:40 +0000416 return 0;
Chris Lattner458cd9c2009-03-10 23:21:44 +0000417 }
Mike Stump1eb44332009-09-09 15:08:12 +0000418
Chris Lattner3182db12009-03-10 23:51:40 +0000419 char CurChar = *CurPtr++;
Chris Lattner018b54e2010-04-05 18:44:00 +0000420 switch (CurChar) {
421 case '$': CurStringPiece += "$$"; continue;
Chris Lattner9bffb072010-04-23 16:29:58 +0000422 case '{': CurStringPiece += (HasVariants ? "$(" : "{"); continue;
423 case '|': CurStringPiece += (HasVariants ? "$|" : "|"); continue;
424 case '}': CurStringPiece += (HasVariants ? "$)" : "}"); continue;
Chris Lattner018b54e2010-04-05 18:44:00 +0000425 case '%':
426 break;
427 default:
Chris Lattner458cd9c2009-03-10 23:21:44 +0000428 CurStringPiece += CurChar;
429 continue;
430 }
Sean Huntc3021132010-05-05 15:23:54 +0000431
Chris Lattner458cd9c2009-03-10 23:21:44 +0000432 // Escaped "%" character in asm string.
Chris Lattnereab8cfb2009-03-11 00:06:36 +0000433 if (CurPtr == StrEnd) {
434 // % at end of string is invalid (no escape).
435 DiagOffs = CurPtr-StrStart-1;
436 return diag::err_asm_invalid_escape;
437 }
Mike Stump1eb44332009-09-09 15:08:12 +0000438
Chris Lattner3182db12009-03-10 23:51:40 +0000439 char EscapedChar = *CurPtr++;
Chris Lattner458cd9c2009-03-10 23:21:44 +0000440 if (EscapedChar == '%') { // %% -> %
441 // Escaped percentage sign.
442 CurStringPiece += '%';
443 continue;
444 }
Mike Stump1eb44332009-09-09 15:08:12 +0000445
Chris Lattner458cd9c2009-03-10 23:21:44 +0000446 if (EscapedChar == '=') { // %= -> Generate an unique ID.
447 CurStringPiece += "${:uid}";
448 continue;
449 }
Mike Stump1eb44332009-09-09 15:08:12 +0000450
Chris Lattner458cd9c2009-03-10 23:21:44 +0000451 // Otherwise, we have an operand. If we have accumulated a string so far,
452 // add it to the Pieces list.
453 if (!CurStringPiece.empty()) {
454 Pieces.push_back(AsmStringPiece(CurStringPiece));
455 CurStringPiece.clear();
456 }
Mike Stump1eb44332009-09-09 15:08:12 +0000457
Chris Lattner458cd9c2009-03-10 23:21:44 +0000458 // Handle %x4 and %x[foo] by capturing x as the modifier character.
459 char Modifier = '\0';
460 if (isalpha(EscapedChar)) {
Benjamin Kramerbc57f3c2011-07-05 11:13:37 +0000461 if (CurPtr == StrEnd) { // Premature end.
462 DiagOffs = CurPtr-StrStart-1;
463 return diag::err_asm_invalid_escape;
464 }
Chris Lattner458cd9c2009-03-10 23:21:44 +0000465 Modifier = EscapedChar;
Chris Lattner3182db12009-03-10 23:51:40 +0000466 EscapedChar = *CurPtr++;
Chris Lattner458cd9c2009-03-10 23:21:44 +0000467 }
Mike Stump1eb44332009-09-09 15:08:12 +0000468
Chris Lattner458cd9c2009-03-10 23:21:44 +0000469 if (isdigit(EscapedChar)) {
470 // %n - Assembler operand n
Chris Lattnercafc2222009-03-11 22:52:17 +0000471 unsigned N = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000472
Chris Lattnercafc2222009-03-11 22:52:17 +0000473 --CurPtr;
474 while (CurPtr != StrEnd && isdigit(*CurPtr))
Chris Lattner32a47ed2009-03-11 23:09:16 +0000475 N = N*10 + ((*CurPtr++)-'0');
Mike Stump1eb44332009-09-09 15:08:12 +0000476
Chris Lattner85759272009-03-11 00:23:13 +0000477 unsigned NumOperands =
478 getNumOutputs() + getNumPlusOperands() + getNumInputs();
479 if (N >= NumOperands) {
480 DiagOffs = CurPtr-StrStart-1;
481 return diag::err_asm_invalid_operand_number;
482 }
483
Chris Lattner458cd9c2009-03-10 23:21:44 +0000484 Pieces.push_back(AsmStringPiece(N, Modifier));
485 continue;
486 }
Mike Stump1eb44332009-09-09 15:08:12 +0000487
Chris Lattner458cd9c2009-03-10 23:21:44 +0000488 // Handle %[foo], a symbolic operand reference.
489 if (EscapedChar == '[') {
Chris Lattnereab8cfb2009-03-11 00:06:36 +0000490 DiagOffs = CurPtr-StrStart-1;
Mike Stump1eb44332009-09-09 15:08:12 +0000491
Chris Lattnereab8cfb2009-03-11 00:06:36 +0000492 // Find the ']'.
Chris Lattner3182db12009-03-10 23:51:40 +0000493 const char *NameEnd = (const char*)memchr(CurPtr, ']', StrEnd-CurPtr);
Chris Lattnereab8cfb2009-03-11 00:06:36 +0000494 if (NameEnd == 0)
495 return diag::err_asm_unterminated_symbolic_operand_name;
496 if (NameEnd == CurPtr)
497 return diag::err_asm_empty_symbolic_operand_name;
Mike Stump1eb44332009-09-09 15:08:12 +0000498
Chris Lattner5f9e2722011-07-23 10:55:15 +0000499 StringRef SymbolicName(CurPtr, NameEnd - CurPtr);
Mike Stump1eb44332009-09-09 15:08:12 +0000500
Chris Lattner458cd9c2009-03-10 23:21:44 +0000501 int N = getNamedOperand(SymbolicName);
Chris Lattnereab8cfb2009-03-11 00:06:36 +0000502 if (N == -1) {
503 // Verify that an operand with that name exists.
504 DiagOffs = CurPtr-StrStart;
505 return diag::err_asm_unknown_symbolic_operand_name;
506 }
Chris Lattner458cd9c2009-03-10 23:21:44 +0000507 Pieces.push_back(AsmStringPiece(N, Modifier));
Mike Stump1eb44332009-09-09 15:08:12 +0000508
Chris Lattnereab8cfb2009-03-11 00:06:36 +0000509 CurPtr = NameEnd+1;
Chris Lattner458cd9c2009-03-10 23:21:44 +0000510 continue;
511 }
Mike Stump1eb44332009-09-09 15:08:12 +0000512
Chris Lattner2ff0f422009-03-10 23:57:07 +0000513 DiagOffs = CurPtr-StrStart-1;
Chris Lattner3182db12009-03-10 23:51:40 +0000514 return diag::err_asm_invalid_escape;
Chris Lattner458cd9c2009-03-10 23:21:44 +0000515 }
516}
517
Sam Weinigb0e4cb62010-02-03 02:09:59 +0000518QualType CXXCatchStmt::getCaughtType() const {
519 if (ExceptionDecl)
520 return ExceptionDecl->getType();
521 return QualType();
522}
523
Chris Lattnerdb6ed172008-01-30 05:01:46 +0000524//===----------------------------------------------------------------------===//
525// Constructors
526//===----------------------------------------------------------------------===//
527
Sean Huntc3021132010-05-05 15:23:54 +0000528AsmStmt::AsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple,
529 bool isvolatile, bool msasm,
Anders Carlsson966146e2010-01-30 23:19:41 +0000530 unsigned numoutputs, unsigned numinputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000531 IdentifierInfo **names, StringLiteral **constraints,
Chris Lattnerdb6ed172008-01-30 05:01:46 +0000532 Expr **exprs, StringLiteral *asmstr, unsigned numclobbers,
533 StringLiteral **clobbers, SourceLocation rparenloc)
Anders Carlssonb235fc22007-11-22 01:36:19 +0000534 : Stmt(AsmStmtClass), AsmLoc(asmloc), RParenLoc(rparenloc), AsmStr(asmstr)
Mike Stump3b11fd32010-01-04 22:37:17 +0000535 , IsSimple(issimple), IsVolatile(isvolatile), MSAsm(msasm)
Anders Carlsson966146e2010-01-30 23:19:41 +0000536 , NumOutputs(numoutputs), NumInputs(numinputs), NumClobbers(numclobbers) {
Nico Weber608b17f2008-08-05 23:15:29 +0000537
Anders Carlsson966146e2010-01-30 23:19:41 +0000538 unsigned NumExprs = NumOutputs +NumInputs;
Sean Huntc3021132010-05-05 15:23:54 +0000539
Anders Carlsson966146e2010-01-30 23:19:41 +0000540 Names = new (C) IdentifierInfo*[NumExprs];
541 std::copy(names, names + NumExprs, Names);
542
543 Exprs = new (C) Stmt*[NumExprs];
544 std::copy(exprs, exprs + NumExprs, Exprs);
545
546 Constraints = new (C) StringLiteral*[NumExprs];
547 std::copy(constraints, constraints + NumExprs, Constraints);
548
549 Clobbers = new (C) StringLiteral*[NumClobbers];
550 std::copy(clobbers, clobbers + NumClobbers, Clobbers);
Anders Carlssonb235fc22007-11-22 01:36:19 +0000551}
552
Chris Lattnerdb6ed172008-01-30 05:01:46 +0000553ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect,
554 Stmt *Body, SourceLocation FCL,
Nico Weber608b17f2008-08-05 23:15:29 +0000555 SourceLocation RPL)
Chris Lattnerdb6ed172008-01-30 05:01:46 +0000556: Stmt(ObjCForCollectionStmtClass) {
557 SubExprs[ELEM] = Elem;
558 SubExprs[COLLECTION] = reinterpret_cast<Stmt*>(Collect);
559 SubExprs[BODY] = Body;
560 ForLoc = FCL;
561 RParenLoc = RPL;
562}
563
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000564ObjCAtTryStmt::ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt,
565 Stmt **CatchStmts, unsigned NumCatchStmts,
566 Stmt *atFinallyStmt)
567 : Stmt(ObjCAtTryStmtClass), AtTryLoc(atTryLoc),
568 NumCatchStmts(NumCatchStmts), HasFinally(atFinallyStmt != 0)
569{
570 Stmt **Stmts = getStmts();
571 Stmts[0] = atTryStmt;
572 for (unsigned I = 0; I != NumCatchStmts; ++I)
573 Stmts[I + 1] = CatchStmts[I];
Sean Huntc3021132010-05-05 15:23:54 +0000574
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000575 if (HasFinally)
576 Stmts[NumCatchStmts + 1] = atFinallyStmt;
577}
Chris Lattnerdb6ed172008-01-30 05:01:46 +0000578
Sean Huntc3021132010-05-05 15:23:54 +0000579ObjCAtTryStmt *ObjCAtTryStmt::Create(ASTContext &Context,
580 SourceLocation atTryLoc,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000581 Stmt *atTryStmt,
Sean Huntc3021132010-05-05 15:23:54 +0000582 Stmt **CatchStmts,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000583 unsigned NumCatchStmts,
584 Stmt *atFinallyStmt) {
Sean Huntc3021132010-05-05 15:23:54 +0000585 unsigned Size = sizeof(ObjCAtTryStmt) +
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000586 (1 + NumCatchStmts + (atFinallyStmt != 0)) * sizeof(Stmt *);
Chris Lattner32488542010-10-30 05:14:06 +0000587 void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>());
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000588 return new (Mem) ObjCAtTryStmt(atTryLoc, atTryStmt, CatchStmts, NumCatchStmts,
589 atFinallyStmt);
590}
Ted Kremenekff981022008-02-01 21:28:59 +0000591
Sean Huntc3021132010-05-05 15:23:54 +0000592ObjCAtTryStmt *ObjCAtTryStmt::CreateEmpty(ASTContext &Context,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000593 unsigned NumCatchStmts,
594 bool HasFinally) {
Sean Huntc3021132010-05-05 15:23:54 +0000595 unsigned Size = sizeof(ObjCAtTryStmt) +
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000596 (1 + NumCatchStmts + HasFinally) * sizeof(Stmt *);
Chris Lattner32488542010-10-30 05:14:06 +0000597 void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>());
Sean Huntc3021132010-05-05 15:23:54 +0000598 return new (Mem) ObjCAtTryStmt(EmptyShell(), NumCatchStmts, HasFinally);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000599}
Nico Weber608b17f2008-08-05 23:15:29 +0000600
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000601SourceRange ObjCAtTryStmt::getSourceRange() const {
602 SourceLocation EndLoc;
603 if (HasFinally)
604 EndLoc = getFinallyStmt()->getLocEnd();
605 else if (NumCatchStmts)
606 EndLoc = getCatchStmt(NumCatchStmts - 1)->getLocEnd();
607 else
608 EndLoc = getTryBody()->getLocEnd();
Sean Huntc3021132010-05-05 15:23:54 +0000609
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000610 return SourceRange(AtTryLoc, EndLoc);
Chris Lattnerdb6ed172008-01-30 05:01:46 +0000611}
612
Sam Weiniga1a396d2010-02-03 03:56:39 +0000613CXXTryStmt *CXXTryStmt::Create(ASTContext &C, SourceLocation tryLoc,
Sean Huntc3021132010-05-05 15:23:54 +0000614 Stmt *tryBlock, Stmt **handlers,
Sam Weiniga1a396d2010-02-03 03:56:39 +0000615 unsigned numHandlers) {
616 std::size_t Size = sizeof(CXXTryStmt);
617 Size += ((numHandlers + 1) * sizeof(Stmt));
618
Chris Lattner32488542010-10-30 05:14:06 +0000619 void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>());
Sam Weiniga1a396d2010-02-03 03:56:39 +0000620 return new (Mem) CXXTryStmt(tryLoc, tryBlock, handlers, numHandlers);
621}
622
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000623CXXTryStmt *CXXTryStmt::Create(ASTContext &C, EmptyShell Empty,
624 unsigned numHandlers) {
625 std::size_t Size = sizeof(CXXTryStmt);
626 Size += ((numHandlers + 1) * sizeof(Stmt));
627
Chris Lattner32488542010-10-30 05:14:06 +0000628 void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>());
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000629 return new (Mem) CXXTryStmt(Empty, numHandlers);
630}
631
Sam Weiniga1a396d2010-02-03 03:56:39 +0000632CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock,
Sam Weinigb0e4cb62010-02-03 02:09:59 +0000633 Stmt **handlers, unsigned numHandlers)
634 : Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(numHandlers) {
Sam Weiniga1a396d2010-02-03 03:56:39 +0000635 Stmt **Stmts = reinterpret_cast<Stmt **>(this + 1);
Sam Weinigb0e4cb62010-02-03 02:09:59 +0000636 Stmts[0] = tryBlock;
637 std::copy(handlers, handlers + NumHandlers, Stmts + 1);
638}
639
Richard Smithad762fc2011-04-14 22:09:26 +0000640CXXForRangeStmt::CXXForRangeStmt(DeclStmt *Range, DeclStmt *BeginEndStmt,
641 Expr *Cond, Expr *Inc, DeclStmt *LoopVar,
642 Stmt *Body, SourceLocation FL,
643 SourceLocation CL, SourceLocation RPL)
644 : Stmt(CXXForRangeStmtClass), ForLoc(FL), ColonLoc(CL), RParenLoc(RPL) {
645 SubExprs[RANGE] = Range;
646 SubExprs[BEGINEND] = BeginEndStmt;
647 SubExprs[COND] = reinterpret_cast<Stmt*>(Cond);
648 SubExprs[INC] = reinterpret_cast<Stmt*>(Inc);
649 SubExprs[LOOPVAR] = LoopVar;
650 SubExprs[BODY] = Body;
651}
652
653Expr *CXXForRangeStmt::getRangeInit() {
654 DeclStmt *RangeStmt = getRangeStmt();
655 VarDecl *RangeDecl = dyn_cast_or_null<VarDecl>(RangeStmt->getSingleDecl());
656 assert(RangeDecl &&& "for-range should have a single var decl");
657 return RangeDecl->getInit();
658}
659
660const Expr *CXXForRangeStmt::getRangeInit() const {
661 return const_cast<CXXForRangeStmt*>(this)->getRangeInit();
662}
663
664VarDecl *CXXForRangeStmt::getLoopVariable() {
665 Decl *LV = cast<DeclStmt>(getLoopVarStmt())->getSingleDecl();
666 assert(LV && "No loop variable in CXXForRangeStmt");
667 return cast<VarDecl>(LV);
668}
669
670const VarDecl *CXXForRangeStmt::getLoopVariable() const {
671 return const_cast<CXXForRangeStmt*>(this)->getLoopVariable();
672}
673
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000674IfStmt::IfStmt(ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +0000675 Stmt *then, SourceLocation EL, Stmt *elsev)
676 : Stmt(IfStmtClass), IfLoc(IL), ElseLoc(EL)
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000677{
678 setConditionVariable(C, var);
679 SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
680 SubExprs[THEN] = then;
681 SubExprs[ELSE] = elsev;
682}
683
684VarDecl *IfStmt::getConditionVariable() const {
685 if (!SubExprs[VAR])
686 return 0;
687
688 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
689 return cast<VarDecl>(DS->getSingleDecl());
690}
691
692void IfStmt::setConditionVariable(ASTContext &C, VarDecl *V) {
693 if (!V) {
694 SubExprs[VAR] = 0;
695 return;
696 }
697
Daniel Dunbar96a00142012-03-09 18:35:03 +0000698 SourceRange VarRange = V->getSourceRange();
699 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
700 VarRange.getEnd());
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000701}
702
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000703ForStmt::ForStmt(ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar,
704 Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP,
705 SourceLocation RP)
706 : Stmt(ForStmtClass), ForLoc(FL), LParenLoc(LP), RParenLoc(RP)
707{
708 SubExprs[INIT] = Init;
709 setConditionVariable(C, condVar);
710 SubExprs[COND] = reinterpret_cast<Stmt*>(Cond);
711 SubExprs[INC] = reinterpret_cast<Stmt*>(Inc);
712 SubExprs[BODY] = Body;
713}
714
715VarDecl *ForStmt::getConditionVariable() const {
716 if (!SubExprs[CONDVAR])
717 return 0;
718
719 DeclStmt *DS = cast<DeclStmt>(SubExprs[CONDVAR]);
720 return cast<VarDecl>(DS->getSingleDecl());
721}
722
723void ForStmt::setConditionVariable(ASTContext &C, VarDecl *V) {
724 if (!V) {
725 SubExprs[CONDVAR] = 0;
726 return;
727 }
728
Daniel Dunbar96a00142012-03-09 18:35:03 +0000729 SourceRange VarRange = V->getSourceRange();
730 SubExprs[CONDVAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
731 VarRange.getEnd());
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000732}
733
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000734SwitchStmt::SwitchStmt(ASTContext &C, VarDecl *Var, Expr *cond)
Ted Kremenek780d8852010-09-09 00:06:01 +0000735 : Stmt(SwitchStmtClass), FirstCase(0), AllEnumCasesCovered(0)
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000736{
737 setConditionVariable(C, Var);
738 SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
739 SubExprs[BODY] = NULL;
740}
741
742VarDecl *SwitchStmt::getConditionVariable() const {
743 if (!SubExprs[VAR])
744 return 0;
745
746 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
747 return cast<VarDecl>(DS->getSingleDecl());
748}
749
750void SwitchStmt::setConditionVariable(ASTContext &C, VarDecl *V) {
751 if (!V) {
752 SubExprs[VAR] = 0;
753 return;
754 }
755
Daniel Dunbar96a00142012-03-09 18:35:03 +0000756 SourceRange VarRange = V->getSourceRange();
757 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
758 VarRange.getEnd());
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000759}
760
John McCall63c00d72011-02-09 08:16:59 +0000761Stmt *SwitchCase::getSubStmt() {
Chris Lattnerc4002c72011-02-28 00:18:06 +0000762 if (isa<CaseStmt>(this))
763 return cast<CaseStmt>(this)->getSubStmt();
John McCall63c00d72011-02-09 08:16:59 +0000764 return cast<DefaultStmt>(this)->getSubStmt();
765}
766
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000767WhileStmt::WhileStmt(ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
768 SourceLocation WL)
Chris Lattnerc4002c72011-02-28 00:18:06 +0000769 : Stmt(WhileStmtClass) {
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000770 setConditionVariable(C, Var);
771 SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
772 SubExprs[BODY] = body;
773 WhileLoc = WL;
774}
775
776VarDecl *WhileStmt::getConditionVariable() const {
777 if (!SubExprs[VAR])
778 return 0;
779
780 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
781 return cast<VarDecl>(DS->getSingleDecl());
782}
783
784void WhileStmt::setConditionVariable(ASTContext &C, VarDecl *V) {
785 if (!V) {
786 SubExprs[VAR] = 0;
787 return;
788 }
Daniel Dunbar96a00142012-03-09 18:35:03 +0000789
790 SourceRange VarRange = V->getSourceRange();
791 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(),
792 VarRange.getEnd());
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000793}
794
Ted Kremenek82977772007-08-24 21:09:09 +0000795// IndirectGotoStmt
Chris Lattnerad8dcf42011-02-17 07:39:24 +0000796LabelDecl *IndirectGotoStmt::getConstantTarget() {
John McCall95c225d2010-10-28 08:53:48 +0000797 if (AddrLabelExpr *E =
798 dyn_cast<AddrLabelExpr>(getTarget()->IgnoreParenImpCasts()))
799 return E->getLabel();
800 return 0;
801}
Ted Kremenek82977772007-08-24 21:09:09 +0000802
Ted Kremenek82977772007-08-24 21:09:09 +0000803// ReturnStmt
Ted Kremenek1060aff2008-06-17 03:11:08 +0000804const Expr* ReturnStmt::getRetValue() const {
805 return cast_or_null<Expr>(RetExpr);
806}
807Expr* ReturnStmt::getRetValue() {
808 return cast_or_null<Expr>(RetExpr);
Ted Kremenek82977772007-08-24 21:09:09 +0000809}
John Wiegley28bbe4b2011-04-28 01:08:34 +0000810
811SEHTryStmt::SEHTryStmt(bool IsCXXTry,
812 SourceLocation TryLoc,
813 Stmt *TryBlock,
814 Stmt *Handler)
815 : Stmt(SEHTryStmtClass),
816 IsCXXTry(IsCXXTry),
817 TryLoc(TryLoc)
818{
819 Children[TRY] = TryBlock;
820 Children[HANDLER] = Handler;
821}
822
823SEHTryStmt* SEHTryStmt::Create(ASTContext &C,
824 bool IsCXXTry,
825 SourceLocation TryLoc,
826 Stmt *TryBlock,
827 Stmt *Handler) {
828 return new(C) SEHTryStmt(IsCXXTry,TryLoc,TryBlock,Handler);
829}
830
831SEHExceptStmt* SEHTryStmt::getExceptHandler() const {
832 return dyn_cast<SEHExceptStmt>(getHandler());
833}
834
835SEHFinallyStmt* SEHTryStmt::getFinallyHandler() const {
836 return dyn_cast<SEHFinallyStmt>(getHandler());
837}
838
839SEHExceptStmt::SEHExceptStmt(SourceLocation Loc,
840 Expr *FilterExpr,
841 Stmt *Block)
842 : Stmt(SEHExceptStmtClass),
843 Loc(Loc)
844{
845 Children[FILTER_EXPR] = reinterpret_cast<Stmt*>(FilterExpr);
846 Children[BLOCK] = Block;
847}
848
849SEHExceptStmt* SEHExceptStmt::Create(ASTContext &C,
850 SourceLocation Loc,
851 Expr *FilterExpr,
852 Stmt *Block) {
853 return new(C) SEHExceptStmt(Loc,FilterExpr,Block);
854}
855
856SEHFinallyStmt::SEHFinallyStmt(SourceLocation Loc,
857 Stmt *Block)
858 : Stmt(SEHFinallyStmtClass),
859 Loc(Loc),
860 Block(Block)
861{}
862
863SEHFinallyStmt* SEHFinallyStmt::Create(ASTContext &C,
864 SourceLocation Loc,
865 Stmt *Block) {
866 return new(C)SEHFinallyStmt(Loc,Block);
867}