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