Stmt.h revision 5572b94b76a78a35bac32d1ef04907c7a651adba
1//===--- Stmt.h - Classes for representing statements -----------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file was developed by Chris Lattner and is distributed under 6// the University of Illinois Open Source License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines the Stmt interface and subclasses. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_AST_STMT_H 15#define LLVM_CLANG_AST_STMT_H 16 17#include "llvm/Support/Casting.h" 18#include "clang/Basic/SourceLocation.h" 19#include "clang/AST/StmtIterator.h" 20#include "llvm/ADT/SmallVector.h" 21#include "llvm/ADT/iterator" 22#include "llvm/Bitcode/SerializationFwd.h" 23#include <iosfwd> 24 25using llvm::dyn_cast_or_null; 26 27namespace clang { 28 class Expr; 29 class Decl; 30 class ScopedDecl; 31 class IdentifierInfo; 32 class SourceManager; 33 class SwitchStmt; 34 class PrinterHelper; 35 36/// Stmt - This represents one statement. 37/// 38class Stmt { 39public: 40 enum StmtClass { 41#define STMT(N, CLASS, PARENT) CLASS##Class = N, 42#define FIRST_STMT(N) firstStmtConstant = N, 43#define LAST_STMT(N) lastStmtConstant = N, 44#define FIRST_EXPR(N) firstExprConstant = N, 45#define LAST_EXPR(N) lastExprConstant = N 46#include "clang/AST/StmtNodes.def" 47}; 48private: 49 const StmtClass sClass; 50public: 51 Stmt(StmtClass SC) : sClass(SC) { 52 if (Stmt::CollectingStats()) Stmt::addStmtClass(SC); 53 } 54 virtual ~Stmt() {} 55 56 StmtClass getStmtClass() const { return sClass; } 57 const char *getStmtClassName() const; 58 59 /// SourceLocation tokens are not useful in isolation - they are low level 60 /// value objects created/interpreted by SourceManager. We assume AST 61 /// clients will have a pointer to the respective SourceManager. 62 virtual SourceRange getSourceRange() const = 0; 63 SourceLocation getLocStart() const { return getSourceRange().getBegin(); } 64 SourceLocation getLocEnd() const { return getSourceRange().getEnd(); } 65 66 // global temp stats (until we have a per-module visitor) 67 static void addStmtClass(const StmtClass s); 68 static bool CollectingStats(bool enable=false); 69 static void PrintStats(); 70 71 /// dump - This does a local dump of the specified AST fragment. It dumps the 72 /// specified node and a few nodes underneath it, but not the whole subtree. 73 /// This is useful in a debugger. 74 void dump() const; 75 void dump(SourceManager &SM) const; 76 77 /// dumpAll - This does a dump of the specified AST fragment and all subtrees. 78 void dumpAll() const; 79 void dumpAll(SourceManager &SM) const; 80 81 /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST 82 /// back to its original source language syntax. 83 void dumpPretty() const; 84 void printPretty(std::ostream &OS, PrinterHelper* = NULL) const; 85 86 /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz. Only 87 /// works on systems with GraphViz (Mac OS X) or dot+gv installed. 88 void viewAST() const; 89 90 // Implement isa<T> support. 91 static bool classof(const Stmt *) { return true; } 92 93 /// hasImplicitControlFlow - Some statements (e.g. short circuited operations) 94 /// contain implicit control-flow in the order their subexpressions 95 /// are evaluated. This predicate returns true if this statement has 96 /// such implicit control-flow. Such statements are also specially handled 97 /// within CFGs. 98 bool hasImplicitControlFlow() const; 99 100 /// Child Iterators: All subclasses must implement child_begin and child_end 101 /// to permit easy iteration over the substatements/subexpessions of an 102 /// AST node. This permits easy iteration over all nodes in the AST. 103 typedef StmtIterator child_iterator; 104 typedef ConstStmtIterator const_child_iterator; 105 106 virtual child_iterator child_begin() = 0; 107 virtual child_iterator child_end() = 0; 108 109 const_child_iterator child_begin() const { 110 return const_child_iterator(const_cast<Stmt*>(this)->child_begin()); 111 } 112 113 const_child_iterator child_end() const { 114 return const_child_iterator(const_cast<Stmt*>(this)->child_end()); 115 } 116 117 void Emit(llvm::Serializer& S) const; 118 static Stmt* Materialize(llvm::Deserializer& D); 119 120 virtual void directEmit(llvm::Serializer& S) const { 121 // This method will eventually be a pure-virtual function. 122 assert (false && "Not implemented."); 123 } 124}; 125 126/// DeclStmt - Adaptor class for mixing declarations with statements and 127/// expressions. For example, CompoundStmt mixes statements, expressions 128/// and declarations (variables, types). Another example is ForStmt, where 129/// the first statement can be an expression or a declaration. 130/// 131class DeclStmt : public Stmt { 132 ScopedDecl *TheDecl; 133public: 134 DeclStmt(ScopedDecl *D) : Stmt(DeclStmtClass), TheDecl(D) {} 135 136 const ScopedDecl *getDecl() const { return TheDecl; } 137 ScopedDecl *getDecl() { return TheDecl; } 138 139 virtual SourceRange getSourceRange() const { return SourceRange(); } 140 141 static bool classof(const Stmt *T) { 142 return T->getStmtClass() == DeclStmtClass; 143 } 144 static bool classof(const DeclStmt *) { return true; } 145 146 // Iterators 147 virtual child_iterator child_begin(); 148 virtual child_iterator child_end(); 149 150 virtual void directEmit(llvm::Serializer& S) const; 151 static DeclStmt* directMaterialize(llvm::Deserializer& D); 152}; 153 154/// NullStmt - This is the null statement ";": C99 6.8.3p3. 155/// 156class NullStmt : public Stmt { 157 SourceLocation SemiLoc; 158public: 159 NullStmt(SourceLocation L) : Stmt(NullStmtClass), SemiLoc(L) {} 160 161 SourceLocation getSemiLoc() const { return SemiLoc; } 162 163 virtual SourceRange getSourceRange() const { return SourceRange(SemiLoc); } 164 165 static bool classof(const Stmt *T) { 166 return T->getStmtClass() == NullStmtClass; 167 } 168 static bool classof(const NullStmt *) { return true; } 169 170 // Iterators 171 virtual child_iterator child_begin(); 172 virtual child_iterator child_end(); 173 174 virtual void directEmit(llvm::Serializer& S) const; 175 static NullStmt* directMaterialize(llvm::Deserializer& D); 176}; 177 178/// CompoundStmt - This represents a group of statements like { stmt stmt }. 179/// 180class CompoundStmt : public Stmt { 181 llvm::SmallVector<Stmt*, 16> Body; 182 SourceLocation LBracLoc, RBracLoc; 183public: 184 CompoundStmt(Stmt **StmtStart, unsigned NumStmts, 185 SourceLocation LB, SourceLocation RB) 186 : Stmt(CompoundStmtClass), Body(StmtStart, StmtStart+NumStmts), 187 LBracLoc(LB), RBracLoc(RB) {} 188 189 bool body_empty() const { return Body.empty(); } 190 191 typedef llvm::SmallVector<Stmt*, 16>::iterator body_iterator; 192 body_iterator body_begin() { return Body.begin(); } 193 body_iterator body_end() { return Body.end(); } 194 Stmt *body_back() { return Body.back(); } 195 196 typedef llvm::SmallVector<Stmt*, 16>::const_iterator const_body_iterator; 197 const_body_iterator body_begin() const { return Body.begin(); } 198 const_body_iterator body_end() const { return Body.end(); } 199 const Stmt *body_back() const { return Body.back(); } 200 201 typedef llvm::SmallVector<Stmt*, 16>::reverse_iterator reverse_body_iterator; 202 reverse_body_iterator body_rbegin() { return Body.rbegin(); } 203 reverse_body_iterator body_rend() { return Body.rend(); } 204 205 typedef llvm::SmallVector<Stmt*, 16>::const_reverse_iterator 206 const_reverse_body_iterator; 207 const_reverse_body_iterator body_rbegin() const { return Body.rbegin(); } 208 const_reverse_body_iterator body_rend() const { return Body.rend(); } 209 210 void push_back(Stmt *S) { Body.push_back(S); } 211 212 virtual SourceRange getSourceRange() const { 213 return SourceRange(LBracLoc, RBracLoc); 214 } 215 216 SourceLocation getLBracLoc() const { return LBracLoc; } 217 SourceLocation getRBracLoc() const { return RBracLoc; } 218 219 static bool classof(const Stmt *T) { 220 return T->getStmtClass() == CompoundStmtClass; 221 } 222 static bool classof(const CompoundStmt *) { return true; } 223 224 // Iterators 225 virtual child_iterator child_begin(); 226 virtual child_iterator child_end(); 227 228 virtual void directEmit(llvm::Serializer& S) const; 229 static CompoundStmt* directMaterialize(llvm::Deserializer& D); 230}; 231 232// SwitchCase is the base class for CaseStmt and DefaultStmt, 233class SwitchCase : public Stmt { 234 // A pointer to the following CaseStmt or DefaultStmt class, 235 // used by SwitchStmt. 236 SwitchCase *NextSwitchCase; 237protected: 238 SwitchCase(StmtClass SC) : Stmt(SC), NextSwitchCase(0) {} 239 240public: 241 const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; } 242 243 SwitchCase *getNextSwitchCase() { return NextSwitchCase; } 244 245 void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; } 246 247 virtual Stmt* v_getSubStmt() = 0; 248 Stmt *getSubStmt() { return v_getSubStmt(); } 249 250 virtual SourceRange getSourceRange() const { return SourceRange(); } 251 252 static bool classof(const Stmt *T) { 253 return T->getStmtClass() == CaseStmtClass || 254 T->getStmtClass() == DefaultStmtClass; 255 } 256 static bool classof(const SwitchCase *) { return true; } 257}; 258 259class CaseStmt : public SwitchCase { 260 enum { SUBSTMT, LHS, RHS, END_EXPR }; 261 Stmt* SubExprs[END_EXPR]; // The expression for the RHS is Non-null for 262 // GNU "case 1 ... 4" extension 263 SourceLocation CaseLoc; 264public: 265 CaseStmt(Expr *lhs, Expr *rhs, Stmt *substmt, SourceLocation caseLoc) 266 : SwitchCase(CaseStmtClass) { 267 SubExprs[SUBSTMT] = substmt; 268 SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs); 269 SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs); 270 CaseLoc = caseLoc; 271 } 272 273 SourceLocation getCaseLoc() const { return CaseLoc; } 274 275 Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); } 276 Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); } 277 Stmt *getSubStmt() { return SubExprs[SUBSTMT]; } 278 virtual Stmt* v_getSubStmt() { return getSubStmt(); } 279 const Expr *getLHS() const { 280 return reinterpret_cast<const Expr*>(SubExprs[LHS]); 281 } 282 const Expr *getRHS() const { 283 return reinterpret_cast<const Expr*>(SubExprs[RHS]); 284 } 285 const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; } 286 287 virtual SourceRange getSourceRange() const { 288 return SourceRange(CaseLoc, SubExprs[SUBSTMT]->getLocEnd()); 289 } 290 static bool classof(const Stmt *T) { 291 return T->getStmtClass() == CaseStmtClass; 292 } 293 static bool classof(const CaseStmt *) { return true; } 294 295 // Iterators 296 virtual child_iterator child_begin(); 297 virtual child_iterator child_end(); 298 299 virtual void directEmit(llvm::Serializer& S) const; 300 static CaseStmt* directMaterialize(llvm::Deserializer& D); 301}; 302 303class DefaultStmt : public SwitchCase { 304 Stmt* SubStmt; 305 SourceLocation DefaultLoc; 306public: 307 DefaultStmt(SourceLocation DL, Stmt *substmt) : 308 SwitchCase(DefaultStmtClass), SubStmt(substmt), DefaultLoc(DL) {} 309 310 Stmt *getSubStmt() { return SubStmt; } 311 virtual Stmt* v_getSubStmt() { return getSubStmt(); } 312 const Stmt *getSubStmt() const { return SubStmt; } 313 314 SourceLocation getDefaultLoc() const { return DefaultLoc; } 315 316 virtual SourceRange getSourceRange() const { 317 return SourceRange(DefaultLoc, SubStmt->getLocEnd()); 318 } 319 static bool classof(const Stmt *T) { 320 return T->getStmtClass() == DefaultStmtClass; 321 } 322 static bool classof(const DefaultStmt *) { return true; } 323 324 // Iterators 325 virtual child_iterator child_begin(); 326 virtual child_iterator child_end(); 327 328 virtual void directEmit(llvm::Serializer& S) const; 329 static DefaultStmt* directMaterialize(llvm::Deserializer& D); 330}; 331 332class LabelStmt : public Stmt { 333 IdentifierInfo *Label; 334 Stmt *SubStmt; 335 SourceLocation IdentLoc; 336public: 337 LabelStmt(SourceLocation IL, IdentifierInfo *label, Stmt *substmt) 338 : Stmt(LabelStmtClass), Label(label), 339 SubStmt(substmt), IdentLoc(IL) {} 340 341 SourceLocation getIdentLoc() const { return IdentLoc; } 342 IdentifierInfo *getID() const { return Label; } 343 const char *getName() const; 344 Stmt *getSubStmt() { return SubStmt; } 345 const Stmt *getSubStmt() const { return SubStmt; } 346 347 void setIdentLoc(SourceLocation L) { IdentLoc = L; } 348 void setSubStmt(Stmt *SS) { SubStmt = SS; } 349 350 virtual SourceRange getSourceRange() const { 351 return SourceRange(IdentLoc, SubStmt->getLocEnd()); 352 } 353 static bool classof(const Stmt *T) { 354 return T->getStmtClass() == LabelStmtClass; 355 } 356 static bool classof(const LabelStmt *) { return true; } 357 358 // Iterators 359 virtual child_iterator child_begin(); 360 virtual child_iterator child_end(); 361 362 virtual void directEmit(llvm::Serializer& S) const; 363 static LabelStmt* directMaterialize(llvm::Deserializer& D); 364}; 365 366 367/// IfStmt - This represents an if/then/else. 368/// 369class IfStmt : public Stmt { 370 enum { COND, THEN, ELSE, END_EXPR }; 371 Stmt* SubExprs[END_EXPR]; 372 SourceLocation IfLoc; 373public: 374 IfStmt(SourceLocation IL, Expr *cond, Stmt *then, Stmt *elsev = 0) 375 : Stmt(IfStmtClass) { 376 SubExprs[COND] = reinterpret_cast<Stmt*>(cond); 377 SubExprs[THEN] = then; 378 SubExprs[ELSE] = elsev; 379 IfLoc = IL; 380 } 381 382 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 383 const Stmt *getThen() const { return SubExprs[THEN]; } 384 const Stmt *getElse() const { return SubExprs[ELSE]; } 385 386 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 387 Stmt *getThen() { return SubExprs[THEN]; } 388 Stmt *getElse() { return SubExprs[ELSE]; } 389 390 virtual SourceRange getSourceRange() const { 391 if (SubExprs[ELSE]) 392 return SourceRange(IfLoc, SubExprs[ELSE]->getLocEnd()); 393 else 394 return SourceRange(IfLoc, SubExprs[THEN]->getLocEnd()); 395 } 396 397 static bool classof(const Stmt *T) { 398 return T->getStmtClass() == IfStmtClass; 399 } 400 static bool classof(const IfStmt *) { return true; } 401 402 // Iterators 403 virtual child_iterator child_begin(); 404 virtual child_iterator child_end(); 405 406 virtual void directEmit(llvm::Serializer& S) const; 407 static IfStmt* directMaterialize(llvm::Deserializer& D); 408}; 409 410/// SwitchStmt - This represents a 'switch' stmt. 411/// 412class SwitchStmt : public Stmt { 413 enum { COND, BODY, END_EXPR }; 414 Stmt* SubExprs[END_EXPR]; 415 // This points to a linked list of case and default statements. 416 SwitchCase *FirstCase; 417 SourceLocation SwitchLoc; 418public: 419 SwitchStmt(Expr *cond) : Stmt(SwitchStmtClass), FirstCase(0) { 420 SubExprs[COND] = reinterpret_cast<Stmt*>(cond); 421 SubExprs[BODY] = NULL; 422 } 423 424 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 425 const Stmt *getBody() const { return SubExprs[BODY]; } 426 const SwitchCase *getSwitchCaseList() const { return FirstCase; } 427 428 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);} 429 Stmt *getBody() { return SubExprs[BODY]; } 430 SwitchCase *getSwitchCaseList() { return FirstCase; } 431 432 void setBody(Stmt *S, SourceLocation SL) { 433 SubExprs[BODY] = S; 434 SwitchLoc = SL; 435 } 436 void addSwitchCase(SwitchCase *SC) { 437 if (FirstCase) 438 SC->setNextSwitchCase(FirstCase); 439 440 FirstCase = SC; 441 } 442 virtual SourceRange getSourceRange() const { 443 return SourceRange(SwitchLoc, SubExprs[BODY]->getLocEnd()); 444 } 445 static bool classof(const Stmt *T) { 446 return T->getStmtClass() == SwitchStmtClass; 447 } 448 static bool classof(const SwitchStmt *) { return true; } 449 450 // Iterators 451 virtual child_iterator child_begin(); 452 virtual child_iterator child_end(); 453 454 virtual void directEmit(llvm::Serializer& S) const; 455 static SwitchStmt* directMaterialize(llvm::Deserializer& D); 456}; 457 458 459/// WhileStmt - This represents a 'while' stmt. 460/// 461class WhileStmt : public Stmt { 462 enum { COND, BODY, END_EXPR }; 463 Stmt* SubExprs[END_EXPR]; 464 SourceLocation WhileLoc; 465public: 466 WhileStmt(Expr *cond, Stmt *body, SourceLocation WL) : Stmt(WhileStmtClass) { 467 SubExprs[COND] = reinterpret_cast<Stmt*>(cond); 468 SubExprs[BODY] = body; 469 WhileLoc = WL; 470 } 471 472 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 473 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 474 Stmt *getBody() { return SubExprs[BODY]; } 475 const Stmt *getBody() const { return SubExprs[BODY]; } 476 477 virtual SourceRange getSourceRange() const { 478 return SourceRange(WhileLoc, SubExprs[BODY]->getLocEnd()); 479 } 480 static bool classof(const Stmt *T) { 481 return T->getStmtClass() == WhileStmtClass; 482 } 483 static bool classof(const WhileStmt *) { return true; } 484 485 // Iterators 486 virtual child_iterator child_begin(); 487 virtual child_iterator child_end(); 488 489 virtual void directEmit(llvm::Serializer& S) const; 490 static WhileStmt* directMaterialize(llvm::Deserializer& D); 491}; 492 493/// DoStmt - This represents a 'do/while' stmt. 494/// 495class DoStmt : public Stmt { 496 enum { COND, BODY, END_EXPR }; 497 Stmt* SubExprs[END_EXPR]; 498 SourceLocation DoLoc; 499public: 500 DoStmt(Stmt *body, Expr *cond, SourceLocation DL) 501 : Stmt(DoStmtClass), DoLoc(DL) { 502 SubExprs[COND] = reinterpret_cast<Stmt*>(cond); 503 SubExprs[BODY] = body; 504 DoLoc = DL; 505 } 506 507 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 508 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 509 Stmt *getBody() { return SubExprs[BODY]; } 510 const Stmt *getBody() const { return SubExprs[BODY]; } 511 512 virtual SourceRange getSourceRange() const { 513 return SourceRange(DoLoc, SubExprs[BODY]->getLocEnd()); 514 } 515 static bool classof(const Stmt *T) { 516 return T->getStmtClass() == DoStmtClass; 517 } 518 static bool classof(const DoStmt *) { return true; } 519 520 // Iterators 521 virtual child_iterator child_begin(); 522 virtual child_iterator child_end(); 523}; 524 525 526/// ForStmt - This represents a 'for (init;cond;inc)' stmt. Note that any of 527/// the init/cond/inc parts of the ForStmt will be null if they were not 528/// specified in the source. 529/// 530class ForStmt : public Stmt { 531 enum { INIT, COND, INC, BODY, END_EXPR }; 532 Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt. 533 SourceLocation ForLoc; 534public: 535 ForStmt(Stmt *Init, Expr *Cond, Expr *Inc, Stmt *Body, SourceLocation FL) 536 : Stmt(ForStmtClass) { 537 SubExprs[INIT] = Init; 538 SubExprs[COND] = reinterpret_cast<Stmt*>(Cond); 539 SubExprs[INC] = reinterpret_cast<Stmt*>(Inc); 540 SubExprs[BODY] = Body; 541 ForLoc = FL; 542 } 543 544 Stmt *getInit() { return SubExprs[INIT]; } 545 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 546 Expr *getInc() { return reinterpret_cast<Expr*>(SubExprs[INC]); } 547 Stmt *getBody() { return SubExprs[BODY]; } 548 549 const Stmt *getInit() const { return SubExprs[INIT]; } 550 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 551 const Expr *getInc() const { return reinterpret_cast<Expr*>(SubExprs[INC]); } 552 const Stmt *getBody() const { return SubExprs[BODY]; } 553 554 virtual SourceRange getSourceRange() const { 555 return SourceRange(ForLoc, SubExprs[BODY]->getLocEnd()); 556 } 557 static bool classof(const Stmt *T) { 558 return T->getStmtClass() == ForStmtClass; 559 } 560 static bool classof(const ForStmt *) { return true; } 561 562 // Iterators 563 virtual child_iterator child_begin(); 564 virtual child_iterator child_end(); 565}; 566 567/// GotoStmt - This represents a direct goto. 568/// 569class GotoStmt : public Stmt { 570 LabelStmt *Label; 571 SourceLocation GotoLoc; 572 SourceLocation LabelLoc; 573public: 574 GotoStmt(LabelStmt *label, SourceLocation GL, SourceLocation LL) 575 : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {} 576 577 LabelStmt *getLabel() const { return Label; } 578 579 virtual SourceRange getSourceRange() const { 580 return SourceRange(GotoLoc, LabelLoc); 581 } 582 static bool classof(const Stmt *T) { 583 return T->getStmtClass() == GotoStmtClass; 584 } 585 static bool classof(const GotoStmt *) { return true; } 586 587 // Iterators 588 virtual child_iterator child_begin(); 589 virtual child_iterator child_end(); 590}; 591 592/// IndirectGotoStmt - This represents an indirect goto. 593/// 594class IndirectGotoStmt : public Stmt { 595 Expr *Target; 596public: 597 IndirectGotoStmt(Expr *target) : Stmt(IndirectGotoStmtClass), Target(target){} 598 599 Expr *getTarget() { return Target; } 600 const Expr *getTarget() const { return Target; } 601 602 virtual SourceRange getSourceRange() const { return SourceRange(); } 603 604 static bool classof(const Stmt *T) { 605 return T->getStmtClass() == IndirectGotoStmtClass; 606 } 607 static bool classof(const IndirectGotoStmt *) { return true; } 608 609 // Iterators 610 virtual child_iterator child_begin(); 611 virtual child_iterator child_end(); 612}; 613 614 615/// ContinueStmt - This represents a continue. 616/// 617class ContinueStmt : public Stmt { 618 SourceLocation ContinueLoc; 619public: 620 ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {} 621 622 virtual SourceRange getSourceRange() const { 623 return SourceRange(ContinueLoc); 624 } 625 static bool classof(const Stmt *T) { 626 return T->getStmtClass() == ContinueStmtClass; 627 } 628 static bool classof(const ContinueStmt *) { return true; } 629 630 // Iterators 631 virtual child_iterator child_begin(); 632 virtual child_iterator child_end(); 633}; 634 635/// BreakStmt - This represents a break. 636/// 637class BreakStmt : public Stmt { 638 SourceLocation BreakLoc; 639public: 640 BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {} 641 642 virtual SourceRange getSourceRange() const { return SourceRange(BreakLoc); } 643 644 static bool classof(const Stmt *T) { 645 return T->getStmtClass() == BreakStmtClass; 646 } 647 static bool classof(const BreakStmt *) { return true; } 648 649 // Iterators 650 virtual child_iterator child_begin(); 651 virtual child_iterator child_end(); 652 653 virtual void directEmit(llvm::Serializer& S) const; 654 static BreakStmt* directMaterialize(llvm::Deserializer& D); 655}; 656 657 658/// ReturnStmt - This represents a return, optionally of an expression. 659/// 660class ReturnStmt : public Stmt { 661 Expr *RetExpr; 662 SourceLocation RetLoc; 663public: 664 ReturnStmt(SourceLocation RL, Expr *E = 0) : Stmt(ReturnStmtClass), 665 RetExpr(E), RetLoc(RL) {} 666 667 const Expr *getRetValue() const { return RetExpr; } 668 Expr *getRetValue() { return RetExpr; } 669 670 virtual SourceRange getSourceRange() const; 671 672 static bool classof(const Stmt *T) { 673 return T->getStmtClass() == ReturnStmtClass; 674 } 675 static bool classof(const ReturnStmt *) { return true; } 676 677 // Iterators 678 virtual child_iterator child_begin(); 679 virtual child_iterator child_end(); 680 681 virtual void directEmit(llvm::Serializer& S) const; 682 static ReturnStmt* directMaterialize(llvm::Deserializer& D); 683}; 684 685/// AsmStmt - This represents a GNU inline-assembly statement extension. 686/// 687class AsmStmt : public Stmt { 688 SourceLocation AsmLoc, RParenLoc; 689 // FIXME: This doesn't capture most of the interesting pieces. 690public: 691 AsmStmt(SourceLocation asmloc, SourceLocation rparenloc) 692 : Stmt(AsmStmtClass), AsmLoc(asmloc), RParenLoc(rparenloc) {} 693 694 virtual SourceRange getSourceRange() const { 695 return SourceRange(AsmLoc, RParenLoc); 696 } 697 698 static bool classof(const Stmt *T) {return T->getStmtClass() == AsmStmtClass;} 699 static bool classof(const AsmStmt *) { return true; } 700 701 virtual child_iterator child_begin(); 702 virtual child_iterator child_end(); 703}; 704 705/// ObjcAtCatchStmt - This represents objective-c's @catch statement. 706class ObjcAtCatchStmt : public Stmt { 707private: 708 // Points to next @catch statement, or null 709 ObjcAtCatchStmt *NextAtCatchStmt; 710 enum { SELECTOR, BODY, END_EXPR }; 711 Stmt *SubExprs[END_EXPR]; 712 SourceLocation AtCatchLoc, RParenLoc; 713 714public: 715 ObjcAtCatchStmt(SourceLocation atCatchLoc, SourceLocation rparenloc, 716 Stmt *catchVarStmtDecl, Stmt *atCatchStmt, Stmt *atCatchList) 717 : Stmt(ObjcAtCatchStmtClass) { 718 SubExprs[SELECTOR] = catchVarStmtDecl; 719 SubExprs[BODY] = atCatchStmt; 720 SubExprs[END_EXPR] = NULL; 721 if (!atCatchList) 722 NextAtCatchStmt = NULL; 723 else { 724 ObjcAtCatchStmt *AtCatchList = 725 static_cast<ObjcAtCatchStmt*>(atCatchList); 726 while (AtCatchList->NextAtCatchStmt) 727 AtCatchList = AtCatchList->NextAtCatchStmt; 728 AtCatchList->NextAtCatchStmt = this; 729 } 730 AtCatchLoc = atCatchLoc; 731 RParenLoc = rparenloc; 732 } 733 734 const Stmt *getCatchBody() const { return SubExprs[BODY]; } 735 Stmt *getCatchBody() { return SubExprs[BODY]; } 736 const ObjcAtCatchStmt *getNextCatchStmt() const { return NextAtCatchStmt; } 737 ObjcAtCatchStmt *getNextCatchStmt() { return NextAtCatchStmt; } 738 const Stmt *getCatchParamStmt() const { return SubExprs[SELECTOR]; } 739 Stmt *getCatchParamStmt() { return SubExprs[SELECTOR]; } 740 741 SourceLocation getRParenLoc() const { return RParenLoc; } 742 743 virtual SourceRange getSourceRange() const { 744 return SourceRange(AtCatchLoc, SubExprs[BODY]->getLocEnd()); 745 } 746 747 static bool classof(const Stmt *T) { 748 return T->getStmtClass() == ObjcAtCatchStmtClass; 749 } 750 static bool classof(const ObjcAtCatchStmt *) { return true; } 751 752 virtual child_iterator child_begin(); 753 virtual child_iterator child_end(); 754 755}; 756 757/// ObjcAtFinallyStmt - This represent objective-c's @finally Statement 758class ObjcAtFinallyStmt : public Stmt { 759 private: 760 Stmt *AtFinallyStmt; 761 SourceLocation AtFinallyLoc; 762 763 public: 764 ObjcAtFinallyStmt(SourceLocation atFinallyLoc, Stmt *atFinallyStmt) 765 : Stmt(ObjcAtFinallyStmtClass), 766 AtFinallyStmt(atFinallyStmt), AtFinallyLoc(atFinallyLoc) {} 767 768 const Stmt *getFinallyBody () const { return AtFinallyStmt; } 769 Stmt *getFinallyBody () { return AtFinallyStmt; } 770 771 virtual SourceRange getSourceRange() const { 772 return SourceRange(AtFinallyLoc, AtFinallyStmt->getLocEnd()); 773 } 774 775 static bool classof(const Stmt *T) { 776 return T->getStmtClass() == ObjcAtFinallyStmtClass; 777 } 778 static bool classof(const ObjcAtFinallyStmt *) { return true; } 779 780 virtual child_iterator child_begin(); 781 virtual child_iterator child_end(); 782 783}; 784 785/// ObjcAtTryStmt - This represent objective-c's over-all 786/// @try ... @catch ... @finally statement. 787class ObjcAtTryStmt : public Stmt { 788private: 789 enum { TRY, CATCH, FINALLY, END_TRY }; 790 Stmt* SubStmts[END_TRY]; 791 792 SourceLocation AtTryLoc; 793 794public: 795 ObjcAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt, 796 Stmt *atCatchStmt, 797 Stmt *atFinallyStmt) 798 : Stmt(ObjcAtTryStmtClass) { 799 SubStmts[TRY] = atTryStmt; 800 SubStmts[CATCH] = atCatchStmt; 801 SubStmts[FINALLY] = atFinallyStmt; 802 SubStmts[END_TRY] = NULL; 803 AtTryLoc = atTryLoc; 804 } 805 806 const Stmt *getTryBody() const { return SubStmts[TRY]; } 807 Stmt *getTryBody() { return SubStmts[TRY]; } 808 const ObjcAtCatchStmt *getCatchStmts() const { 809 return dyn_cast_or_null<ObjcAtCatchStmt>(SubStmts[CATCH]); 810 } 811 ObjcAtCatchStmt *getCatchStmts() { 812 return dyn_cast_or_null<ObjcAtCatchStmt>(SubStmts[CATCH]); 813 } 814 const ObjcAtFinallyStmt *getFinallyStmt() const { 815 return dyn_cast_or_null<ObjcAtFinallyStmt>(SubStmts[FINALLY]); 816 } 817 ObjcAtFinallyStmt *getFinallyStmt() { 818 return dyn_cast_or_null<ObjcAtFinallyStmt>(SubStmts[FINALLY]); 819 } 820 virtual SourceRange getSourceRange() const { 821 return SourceRange(AtTryLoc, SubStmts[TRY]->getLocEnd()); 822 } 823 824 static bool classof(const Stmt *T) { 825 return T->getStmtClass() == ObjcAtTryStmtClass; 826 } 827 static bool classof(const ObjcAtTryStmt *) { return true; } 828 829 virtual child_iterator child_begin(); 830 virtual child_iterator child_end(); 831 832}; 833 834/// ObjcAtThrowStmt - This represents objective-c's @throw statement. 835class ObjcAtThrowStmt : public Stmt { 836private: 837 Stmt *Throw; 838 SourceLocation AtThrowLoc; 839 840public: 841 ObjcAtThrowStmt(SourceLocation atThrowLoc, Stmt *throwExpr) 842 : Stmt(ObjcAtThrowStmtClass), Throw(throwExpr) { 843 AtThrowLoc = atThrowLoc; 844 } 845 846 Expr *const getThrowExpr() const { return reinterpret_cast<Expr*>(Throw); } 847 848 virtual SourceRange getSourceRange() const { 849 return SourceRange(AtThrowLoc, Throw->getLocEnd()); 850 } 851 852 static bool classof(const Stmt *T) { 853 return T->getStmtClass() == ObjcAtThrowStmtClass; 854 } 855 static bool classof(const ObjcAtThrowStmt *) { return true; } 856 857 virtual child_iterator child_begin(); 858 virtual child_iterator child_end(); 859}; 860 861} // end namespace clang 862 863#endif 864