Stmt.h revision 12b95e523c193bac4bdde0b23f2a9777ca956145
1//===--- Stmt.h - Classes for representing statements -----------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// 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 "clang/Basic/LLVM.h" 18#include "clang/Basic/SourceLocation.h" 19#include "clang/AST/PrettyPrinter.h" 20#include "clang/AST/StmtIterator.h" 21#include "clang/AST/DeclGroup.h" 22#include "clang/AST/Attr.h" 23#include "clang/Lex/Token.h" 24#include "llvm/ADT/SmallVector.h" 25#include "llvm/Support/Compiler.h" 26#include "llvm/Support/raw_ostream.h" 27#include <string> 28 29namespace llvm { 30 class FoldingSetNodeID; 31} 32 33namespace clang { 34 class ASTContext; 35 class Expr; 36 class Decl; 37 class ParmVarDecl; 38 class QualType; 39 class IdentifierInfo; 40 class LabelDecl; 41 class SourceManager; 42 class StringLiteral; 43 class SwitchStmt; 44 class VarDecl; 45 46 //===--------------------------------------------------------------------===// 47 // ExprIterator - Iterators for iterating over Stmt* arrays that contain 48 // only Expr*. This is needed because AST nodes use Stmt* arrays to store 49 // references to children (to be compatible with StmtIterator). 50 //===--------------------------------------------------------------------===// 51 52 class Stmt; 53 class Expr; 54 55 class ExprIterator { 56 Stmt** I; 57 public: 58 ExprIterator(Stmt** i) : I(i) {} 59 ExprIterator() : I(0) {} 60 ExprIterator& operator++() { ++I; return *this; } 61 ExprIterator operator-(size_t i) { return I-i; } 62 ExprIterator operator+(size_t i) { return I+i; } 63 Expr* operator[](size_t idx); 64 // FIXME: Verify that this will correctly return a signed distance. 65 signed operator-(const ExprIterator& R) const { return I - R.I; } 66 Expr* operator*() const; 67 Expr* operator->() const; 68 bool operator==(const ExprIterator& R) const { return I == R.I; } 69 bool operator!=(const ExprIterator& R) const { return I != R.I; } 70 bool operator>(const ExprIterator& R) const { return I > R.I; } 71 bool operator>=(const ExprIterator& R) const { return I >= R.I; } 72 }; 73 74 class ConstExprIterator { 75 const Stmt * const *I; 76 public: 77 ConstExprIterator(const Stmt * const *i) : I(i) {} 78 ConstExprIterator() : I(0) {} 79 ConstExprIterator& operator++() { ++I; return *this; } 80 ConstExprIterator operator+(size_t i) const { return I+i; } 81 ConstExprIterator operator-(size_t i) const { return I-i; } 82 const Expr * operator[](size_t idx) const; 83 signed operator-(const ConstExprIterator& R) const { return I - R.I; } 84 const Expr * operator*() const; 85 const Expr * operator->() const; 86 bool operator==(const ConstExprIterator& R) const { return I == R.I; } 87 bool operator!=(const ConstExprIterator& R) const { return I != R.I; } 88 bool operator>(const ConstExprIterator& R) const { return I > R.I; } 89 bool operator>=(const ConstExprIterator& R) const { return I >= R.I; } 90 }; 91 92//===----------------------------------------------------------------------===// 93// AST classes for statements. 94//===----------------------------------------------------------------------===// 95 96/// Stmt - This represents one statement. 97/// 98class Stmt { 99public: 100 enum StmtClass { 101 NoStmtClass = 0, 102#define STMT(CLASS, PARENT) CLASS##Class, 103#define STMT_RANGE(BASE, FIRST, LAST) \ 104 first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class, 105#define LAST_STMT_RANGE(BASE, FIRST, LAST) \ 106 first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class 107#define ABSTRACT_STMT(STMT) 108#include "clang/AST/StmtNodes.inc" 109 }; 110 111 // Make vanilla 'new' and 'delete' illegal for Stmts. 112protected: 113 void* operator new(size_t bytes) throw() { 114 llvm_unreachable("Stmts cannot be allocated with regular 'new'."); 115 } 116 void operator delete(void* data) throw() { 117 llvm_unreachable("Stmts cannot be released with regular 'delete'."); 118 } 119 120 class StmtBitfields { 121 friend class Stmt; 122 123 /// \brief The statement class. 124 unsigned sClass : 8; 125 }; 126 enum { NumStmtBits = 8 }; 127 128 class CompoundStmtBitfields { 129 friend class CompoundStmt; 130 unsigned : NumStmtBits; 131 132 unsigned NumStmts : 32 - NumStmtBits; 133 }; 134 135 class ExprBitfields { 136 friend class Expr; 137 friend class DeclRefExpr; // computeDependence 138 friend class InitListExpr; // ctor 139 friend class DesignatedInitExpr; // ctor 140 friend class BlockDeclRefExpr; // ctor 141 friend class ASTStmtReader; // deserialization 142 friend class CXXNewExpr; // ctor 143 friend class DependentScopeDeclRefExpr; // ctor 144 friend class CXXConstructExpr; // ctor 145 friend class CallExpr; // ctor 146 friend class OffsetOfExpr; // ctor 147 friend class ObjCMessageExpr; // ctor 148 friend class ObjCArrayLiteral; // ctor 149 friend class ObjCDictionaryLiteral; // ctor 150 friend class ShuffleVectorExpr; // ctor 151 friend class ParenListExpr; // ctor 152 friend class CXXUnresolvedConstructExpr; // ctor 153 friend class CXXDependentScopeMemberExpr; // ctor 154 friend class OverloadExpr; // ctor 155 friend class PseudoObjectExpr; // ctor 156 friend class AtomicExpr; // ctor 157 unsigned : NumStmtBits; 158 159 unsigned ValueKind : 2; 160 unsigned ObjectKind : 2; 161 unsigned TypeDependent : 1; 162 unsigned ValueDependent : 1; 163 unsigned InstantiationDependent : 1; 164 unsigned ContainsUnexpandedParameterPack : 1; 165 }; 166 enum { NumExprBits = 16 }; 167 168 class CharacterLiteralBitfields { 169 friend class CharacterLiteral; 170 unsigned : NumExprBits; 171 172 unsigned Kind : 2; 173 }; 174 175 class FloatingLiteralBitfields { 176 friend class FloatingLiteral; 177 unsigned : NumExprBits; 178 179 unsigned IsIEEE : 1; // Distinguishes between PPC128 and IEEE128. 180 unsigned IsExact : 1; 181 }; 182 183 class UnaryExprOrTypeTraitExprBitfields { 184 friend class UnaryExprOrTypeTraitExpr; 185 unsigned : NumExprBits; 186 187 unsigned Kind : 2; 188 unsigned IsType : 1; // true if operand is a type, false if an expression. 189 }; 190 191 class DeclRefExprBitfields { 192 friend class DeclRefExpr; 193 friend class ASTStmtReader; // deserialization 194 unsigned : NumExprBits; 195 196 unsigned HasQualifier : 1; 197 unsigned HasTemplateKWAndArgsInfo : 1; 198 unsigned HasFoundDecl : 1; 199 unsigned HadMultipleCandidates : 1; 200 unsigned RefersToEnclosingLocal : 1; 201 }; 202 203 class CastExprBitfields { 204 friend class CastExpr; 205 unsigned : NumExprBits; 206 207 unsigned Kind : 6; 208 unsigned BasePathSize : 32 - 6 - NumExprBits; 209 }; 210 211 class CallExprBitfields { 212 friend class CallExpr; 213 unsigned : NumExprBits; 214 215 unsigned NumPreArgs : 1; 216 }; 217 218 class ExprWithCleanupsBitfields { 219 friend class ExprWithCleanups; 220 friend class ASTStmtReader; // deserialization 221 222 unsigned : NumExprBits; 223 224 unsigned NumObjects : 32 - NumExprBits; 225 }; 226 227 class PseudoObjectExprBitfields { 228 friend class PseudoObjectExpr; 229 friend class ASTStmtReader; // deserialization 230 231 unsigned : NumExprBits; 232 233 // These don't need to be particularly wide, because they're 234 // strictly limited by the forms of expressions we permit. 235 unsigned NumSubExprs : 8; 236 unsigned ResultIndex : 32 - 8 - NumExprBits; 237 }; 238 239 class ObjCIndirectCopyRestoreExprBitfields { 240 friend class ObjCIndirectCopyRestoreExpr; 241 unsigned : NumExprBits; 242 243 unsigned ShouldCopy : 1; 244 }; 245 246 class InitListExprBitfields { 247 friend class InitListExpr; 248 249 unsigned : NumExprBits; 250 251 /// Whether this initializer list originally had a GNU array-range 252 /// designator in it. This is a temporary marker used by CodeGen. 253 unsigned HadArrayRangeDesignator : 1; 254 255 /// Whether this initializer list initializes a std::initializer_list 256 /// object. 257 unsigned InitializesStdInitializerList : 1; 258 }; 259 260 class TypeTraitExprBitfields { 261 friend class TypeTraitExpr; 262 friend class ASTStmtReader; 263 friend class ASTStmtWriter; 264 265 unsigned : NumExprBits; 266 267 /// \brief The kind of type trait, which is a value of a TypeTrait enumerator. 268 unsigned Kind : 8; 269 270 /// \brief If this expression is not value-dependent, this indicates whether 271 /// the trait evaluated true or false. 272 unsigned Value : 1; 273 274 /// \brief The number of arguments to this type trait. 275 unsigned NumArgs : 32 - 8 - 1 - NumExprBits; 276 }; 277 278 union { 279 // FIXME: this is wasteful on 64-bit platforms. 280 void *Aligner; 281 282 StmtBitfields StmtBits; 283 CompoundStmtBitfields CompoundStmtBits; 284 ExprBitfields ExprBits; 285 CharacterLiteralBitfields CharacterLiteralBits; 286 FloatingLiteralBitfields FloatingLiteralBits; 287 UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits; 288 DeclRefExprBitfields DeclRefExprBits; 289 CastExprBitfields CastExprBits; 290 CallExprBitfields CallExprBits; 291 ExprWithCleanupsBitfields ExprWithCleanupsBits; 292 PseudoObjectExprBitfields PseudoObjectExprBits; 293 ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits; 294 InitListExprBitfields InitListExprBits; 295 TypeTraitExprBitfields TypeTraitExprBits; 296 }; 297 298 friend class ASTStmtReader; 299 friend class ASTStmtWriter; 300 301public: 302 // Only allow allocation of Stmts using the allocator in ASTContext 303 // or by doing a placement new. 304 void* operator new(size_t bytes, ASTContext& C, 305 unsigned alignment = 8) throw() { 306 return ::operator new(bytes, C, alignment); 307 } 308 309 void* operator new(size_t bytes, ASTContext* C, 310 unsigned alignment = 8) throw() { 311 return ::operator new(bytes, *C, alignment); 312 } 313 314 void* operator new(size_t bytes, void* mem) throw() { 315 return mem; 316 } 317 318 void operator delete(void*, ASTContext&, unsigned) throw() { } 319 void operator delete(void*, ASTContext*, unsigned) throw() { } 320 void operator delete(void*, std::size_t) throw() { } 321 void operator delete(void*, void*) throw() { } 322 323public: 324 /// \brief A placeholder type used to construct an empty shell of a 325 /// type, that will be filled in later (e.g., by some 326 /// de-serialization). 327 struct EmptyShell { }; 328 329private: 330 /// \brief Whether statistic collection is enabled. 331 static bool StatisticsEnabled; 332 333protected: 334 /// \brief Construct an empty statement. 335 explicit Stmt(StmtClass SC, EmptyShell) { 336 StmtBits.sClass = SC; 337 if (StatisticsEnabled) Stmt::addStmtClass(SC); 338 } 339 340public: 341 Stmt(StmtClass SC) { 342 StmtBits.sClass = SC; 343 if (StatisticsEnabled) Stmt::addStmtClass(SC); 344 } 345 346 StmtClass getStmtClass() const { 347 return static_cast<StmtClass>(StmtBits.sClass); 348 } 349 const char *getStmtClassName() const; 350 351 /// SourceLocation tokens are not useful in isolation - they are low level 352 /// value objects created/interpreted by SourceManager. We assume AST 353 /// clients will have a pointer to the respective SourceManager. 354 SourceRange getSourceRange() const LLVM_READONLY; 355 SourceLocation getLocStart() const LLVM_READONLY; 356 SourceLocation getLocEnd() const LLVM_READONLY; 357 358 // global temp stats (until we have a per-module visitor) 359 static void addStmtClass(const StmtClass s); 360 static void EnableStatistics(); 361 static void PrintStats(); 362 363 /// dump - This does a local dump of the specified AST fragment. It dumps the 364 /// specified node and a few nodes underneath it, but not the whole subtree. 365 /// This is useful in a debugger. 366 LLVM_ATTRIBUTE_USED void dump() const; 367 LLVM_ATTRIBUTE_USED void dump(SourceManager &SM) const; 368 void dump(raw_ostream &OS, SourceManager &SM) const; 369 370 /// dumpAll - This does a dump of the specified AST fragment and all subtrees. 371 void dumpAll() const; 372 void dumpAll(SourceManager &SM) const; 373 374 /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST 375 /// back to its original source language syntax. 376 void dumpPretty(ASTContext &Context) const; 377 void printPretty(raw_ostream &OS, PrinterHelper *Helper, 378 const PrintingPolicy &Policy, 379 unsigned Indentation = 0) const; 380 381 /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz. Only 382 /// works on systems with GraphViz (Mac OS X) or dot+gv installed. 383 void viewAST() const; 384 385 /// Skip past any implicit AST nodes which might surround this 386 /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes. 387 Stmt *IgnoreImplicit(); 388 389 const Stmt *stripLabelLikeStatements() const; 390 Stmt *stripLabelLikeStatements() { 391 return const_cast<Stmt*>( 392 const_cast<const Stmt*>(this)->stripLabelLikeStatements()); 393 } 394 395 // Implement isa<T> support. 396 static bool classof(const Stmt *) { return true; } 397 398 /// hasImplicitControlFlow - Some statements (e.g. short circuited operations) 399 /// contain implicit control-flow in the order their subexpressions 400 /// are evaluated. This predicate returns true if this statement has 401 /// such implicit control-flow. Such statements are also specially handled 402 /// within CFGs. 403 bool hasImplicitControlFlow() const; 404 405 /// Child Iterators: All subclasses must implement 'children' 406 /// to permit easy iteration over the substatements/subexpessions of an 407 /// AST node. This permits easy iteration over all nodes in the AST. 408 typedef StmtIterator child_iterator; 409 typedef ConstStmtIterator const_child_iterator; 410 411 typedef StmtRange child_range; 412 typedef ConstStmtRange const_child_range; 413 414 child_range children(); 415 const_child_range children() const { 416 return const_cast<Stmt*>(this)->children(); 417 } 418 419 child_iterator child_begin() { return children().first; } 420 child_iterator child_end() { return children().second; } 421 422 const_child_iterator child_begin() const { return children().first; } 423 const_child_iterator child_end() const { return children().second; } 424 425 /// \brief Produce a unique representation of the given statement. 426 /// 427 /// \param ID once the profiling operation is complete, will contain 428 /// the unique representation of the given statement. 429 /// 430 /// \param Context the AST context in which the statement resides 431 /// 432 /// \param Canonical whether the profile should be based on the canonical 433 /// representation of this statement (e.g., where non-type template 434 /// parameters are identified by index/level rather than their 435 /// declaration pointers) or the exact representation of the statement as 436 /// written in the source. 437 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, 438 bool Canonical) const; 439}; 440 441/// DeclStmt - Adaptor class for mixing declarations with statements and 442/// expressions. For example, CompoundStmt mixes statements, expressions 443/// and declarations (variables, types). Another example is ForStmt, where 444/// the first statement can be an expression or a declaration. 445/// 446class DeclStmt : public Stmt { 447 DeclGroupRef DG; 448 SourceLocation StartLoc, EndLoc; 449 450public: 451 DeclStmt(DeclGroupRef dg, SourceLocation startLoc, 452 SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg), 453 StartLoc(startLoc), EndLoc(endLoc) {} 454 455 /// \brief Build an empty declaration statement. 456 explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { } 457 458 /// isSingleDecl - This method returns true if this DeclStmt refers 459 /// to a single Decl. 460 bool isSingleDecl() const { 461 return DG.isSingleDecl(); 462 } 463 464 const Decl *getSingleDecl() const { return DG.getSingleDecl(); } 465 Decl *getSingleDecl() { return DG.getSingleDecl(); } 466 467 const DeclGroupRef getDeclGroup() const { return DG; } 468 DeclGroupRef getDeclGroup() { return DG; } 469 void setDeclGroup(DeclGroupRef DGR) { DG = DGR; } 470 471 SourceLocation getStartLoc() const { return StartLoc; } 472 void setStartLoc(SourceLocation L) { StartLoc = L; } 473 SourceLocation getEndLoc() const { return EndLoc; } 474 void setEndLoc(SourceLocation L) { EndLoc = L; } 475 476 SourceRange getSourceRange() const LLVM_READONLY { 477 return SourceRange(StartLoc, EndLoc); 478 } 479 480 static bool classof(const Stmt *T) { 481 return T->getStmtClass() == DeclStmtClass; 482 } 483 static bool classof(const DeclStmt *) { return true; } 484 485 // Iterators over subexpressions. 486 child_range children() { 487 return child_range(child_iterator(DG.begin(), DG.end()), 488 child_iterator(DG.end(), DG.end())); 489 } 490 491 typedef DeclGroupRef::iterator decl_iterator; 492 typedef DeclGroupRef::const_iterator const_decl_iterator; 493 494 decl_iterator decl_begin() { return DG.begin(); } 495 decl_iterator decl_end() { return DG.end(); } 496 const_decl_iterator decl_begin() const { return DG.begin(); } 497 const_decl_iterator decl_end() const { return DG.end(); } 498 499 typedef std::reverse_iterator<decl_iterator> reverse_decl_iterator; 500 reverse_decl_iterator decl_rbegin() { 501 return reverse_decl_iterator(decl_end()); 502 } 503 reverse_decl_iterator decl_rend() { 504 return reverse_decl_iterator(decl_begin()); 505 } 506}; 507 508/// NullStmt - This is the null statement ";": C99 6.8.3p3. 509/// 510class NullStmt : public Stmt { 511 SourceLocation SemiLoc; 512 513 /// \brief True if the null statement was preceded by an empty macro, e.g: 514 /// @code 515 /// #define CALL(x) 516 /// CALL(0); 517 /// @endcode 518 bool HasLeadingEmptyMacro; 519public: 520 NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false) 521 : Stmt(NullStmtClass), SemiLoc(L), 522 HasLeadingEmptyMacro(hasLeadingEmptyMacro) {} 523 524 /// \brief Build an empty null statement. 525 explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty), 526 HasLeadingEmptyMacro(false) { } 527 528 SourceLocation getSemiLoc() const { return SemiLoc; } 529 void setSemiLoc(SourceLocation L) { SemiLoc = L; } 530 531 bool hasLeadingEmptyMacro() const { return HasLeadingEmptyMacro; } 532 533 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(SemiLoc); } 534 535 static bool classof(const Stmt *T) { 536 return T->getStmtClass() == NullStmtClass; 537 } 538 static bool classof(const NullStmt *) { return true; } 539 540 child_range children() { return child_range(); } 541 542 friend class ASTStmtReader; 543 friend class ASTStmtWriter; 544}; 545 546/// CompoundStmt - This represents a group of statements like { stmt stmt }. 547/// 548class CompoundStmt : public Stmt { 549 Stmt** Body; 550 SourceLocation LBracLoc, RBracLoc; 551public: 552 CompoundStmt(ASTContext &C, Stmt **StmtStart, unsigned NumStmts, 553 SourceLocation LB, SourceLocation RB); 554 555 // \brief Build an empty compound statment with a location. 556 explicit CompoundStmt(SourceLocation Loc) 557 : Stmt(CompoundStmtClass), Body(0), LBracLoc(Loc), RBracLoc(Loc) { 558 CompoundStmtBits.NumStmts = 0; 559 } 560 561 // \brief Build an empty compound statement. 562 explicit CompoundStmt(EmptyShell Empty) 563 : Stmt(CompoundStmtClass, Empty), Body(0) { 564 CompoundStmtBits.NumStmts = 0; 565 } 566 567 void setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts); 568 569 bool body_empty() const { return CompoundStmtBits.NumStmts == 0; } 570 unsigned size() const { return CompoundStmtBits.NumStmts; } 571 572 typedef Stmt** body_iterator; 573 body_iterator body_begin() { return Body; } 574 body_iterator body_end() { return Body + size(); } 575 Stmt *body_back() { return !body_empty() ? Body[size()-1] : 0; } 576 577 void setLastStmt(Stmt *S) { 578 assert(!body_empty() && "setLastStmt"); 579 Body[size()-1] = S; 580 } 581 582 typedef Stmt* const * const_body_iterator; 583 const_body_iterator body_begin() const { return Body; } 584 const_body_iterator body_end() const { return Body + size(); } 585 const Stmt *body_back() const { return !body_empty() ? Body[size()-1] : 0; } 586 587 typedef std::reverse_iterator<body_iterator> reverse_body_iterator; 588 reverse_body_iterator body_rbegin() { 589 return reverse_body_iterator(body_end()); 590 } 591 reverse_body_iterator body_rend() { 592 return reverse_body_iterator(body_begin()); 593 } 594 595 typedef std::reverse_iterator<const_body_iterator> 596 const_reverse_body_iterator; 597 598 const_reverse_body_iterator body_rbegin() const { 599 return const_reverse_body_iterator(body_end()); 600 } 601 602 const_reverse_body_iterator body_rend() const { 603 return const_reverse_body_iterator(body_begin()); 604 } 605 606 SourceRange getSourceRange() const LLVM_READONLY { 607 return SourceRange(LBracLoc, RBracLoc); 608 } 609 610 SourceLocation getLBracLoc() const { return LBracLoc; } 611 void setLBracLoc(SourceLocation L) { LBracLoc = L; } 612 SourceLocation getRBracLoc() const { return RBracLoc; } 613 void setRBracLoc(SourceLocation L) { RBracLoc = L; } 614 615 static bool classof(const Stmt *T) { 616 return T->getStmtClass() == CompoundStmtClass; 617 } 618 static bool classof(const CompoundStmt *) { return true; } 619 620 // Iterators 621 child_range children() { 622 return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts); 623 } 624 625 const_child_range children() const { 626 return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts); 627 } 628}; 629 630// SwitchCase is the base class for CaseStmt and DefaultStmt, 631class SwitchCase : public Stmt { 632protected: 633 // A pointer to the following CaseStmt or DefaultStmt class, 634 // used by SwitchStmt. 635 SwitchCase *NextSwitchCase; 636 637 SwitchCase(StmtClass SC) : Stmt(SC), NextSwitchCase(0) {} 638 639public: 640 const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; } 641 642 SwitchCase *getNextSwitchCase() { return NextSwitchCase; } 643 644 void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; } 645 646 Stmt *getSubStmt(); 647 const Stmt *getSubStmt() const { 648 return const_cast<SwitchCase*>(this)->getSubStmt(); 649 } 650 651 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(); } 652 653 static bool classof(const Stmt *T) { 654 return T->getStmtClass() == CaseStmtClass || 655 T->getStmtClass() == DefaultStmtClass; 656 } 657 static bool classof(const SwitchCase *) { return true; } 658}; 659 660class CaseStmt : public SwitchCase { 661 enum { LHS, RHS, SUBSTMT, END_EXPR }; 662 Stmt* SubExprs[END_EXPR]; // The expression for the RHS is Non-null for 663 // GNU "case 1 ... 4" extension 664 SourceLocation CaseLoc; 665 SourceLocation EllipsisLoc; 666 SourceLocation ColonLoc; 667public: 668 CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc, 669 SourceLocation ellipsisLoc, SourceLocation colonLoc) 670 : SwitchCase(CaseStmtClass) { 671 SubExprs[SUBSTMT] = 0; 672 SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs); 673 SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs); 674 CaseLoc = caseLoc; 675 EllipsisLoc = ellipsisLoc; 676 ColonLoc = colonLoc; 677 } 678 679 /// \brief Build an empty switch case statement. 680 explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass) { } 681 682 SourceLocation getCaseLoc() const { return CaseLoc; } 683 void setCaseLoc(SourceLocation L) { CaseLoc = L; } 684 SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 685 void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; } 686 SourceLocation getColonLoc() const { return ColonLoc; } 687 void setColonLoc(SourceLocation L) { ColonLoc = L; } 688 689 Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); } 690 Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); } 691 Stmt *getSubStmt() { return SubExprs[SUBSTMT]; } 692 693 const Expr *getLHS() const { 694 return reinterpret_cast<const Expr*>(SubExprs[LHS]); 695 } 696 const Expr *getRHS() const { 697 return reinterpret_cast<const Expr*>(SubExprs[RHS]); 698 } 699 const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; } 700 701 void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; } 702 void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); } 703 void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); } 704 705 706 SourceRange getSourceRange() const LLVM_READONLY { 707 // Handle deeply nested case statements with iteration instead of recursion. 708 const CaseStmt *CS = this; 709 while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt())) 710 CS = CS2; 711 712 return SourceRange(CaseLoc, CS->getSubStmt()->getLocEnd()); 713 } 714 static bool classof(const Stmt *T) { 715 return T->getStmtClass() == CaseStmtClass; 716 } 717 static bool classof(const CaseStmt *) { return true; } 718 719 // Iterators 720 child_range children() { 721 return child_range(&SubExprs[0], &SubExprs[END_EXPR]); 722 } 723}; 724 725class DefaultStmt : public SwitchCase { 726 Stmt* SubStmt; 727 SourceLocation DefaultLoc; 728 SourceLocation ColonLoc; 729public: 730 DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) : 731 SwitchCase(DefaultStmtClass), SubStmt(substmt), DefaultLoc(DL), 732 ColonLoc(CL) {} 733 734 /// \brief Build an empty default statement. 735 explicit DefaultStmt(EmptyShell) : SwitchCase(DefaultStmtClass) { } 736 737 Stmt *getSubStmt() { return SubStmt; } 738 const Stmt *getSubStmt() const { return SubStmt; } 739 void setSubStmt(Stmt *S) { SubStmt = S; } 740 741 SourceLocation getDefaultLoc() const { return DefaultLoc; } 742 void setDefaultLoc(SourceLocation L) { DefaultLoc = L; } 743 SourceLocation getColonLoc() const { return ColonLoc; } 744 void setColonLoc(SourceLocation L) { ColonLoc = L; } 745 746 SourceRange getSourceRange() const LLVM_READONLY { 747 return SourceRange(DefaultLoc, SubStmt->getLocEnd()); 748 } 749 static bool classof(const Stmt *T) { 750 return T->getStmtClass() == DefaultStmtClass; 751 } 752 static bool classof(const DefaultStmt *) { return true; } 753 754 // Iterators 755 child_range children() { return child_range(&SubStmt, &SubStmt+1); } 756}; 757 758 759/// LabelStmt - Represents a label, which has a substatement. For example: 760/// foo: return; 761/// 762class LabelStmt : public Stmt { 763 LabelDecl *TheDecl; 764 Stmt *SubStmt; 765 SourceLocation IdentLoc; 766public: 767 LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt) 768 : Stmt(LabelStmtClass), TheDecl(D), SubStmt(substmt), IdentLoc(IL) { 769 } 770 771 // \brief Build an empty label statement. 772 explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { } 773 774 SourceLocation getIdentLoc() const { return IdentLoc; } 775 LabelDecl *getDecl() const { return TheDecl; } 776 void setDecl(LabelDecl *D) { TheDecl = D; } 777 const char *getName() const; 778 Stmt *getSubStmt() { return SubStmt; } 779 const Stmt *getSubStmt() const { return SubStmt; } 780 void setIdentLoc(SourceLocation L) { IdentLoc = L; } 781 void setSubStmt(Stmt *SS) { SubStmt = SS; } 782 783 SourceRange getSourceRange() const LLVM_READONLY { 784 return SourceRange(IdentLoc, SubStmt->getLocEnd()); 785 } 786 child_range children() { return child_range(&SubStmt, &SubStmt+1); } 787 788 static bool classof(const Stmt *T) { 789 return T->getStmtClass() == LabelStmtClass; 790 } 791 static bool classof(const LabelStmt *) { return true; } 792}; 793 794 795/// \brief Represents an attribute applied to a statement. 796/// 797/// Represents an attribute applied to a statement. For example: 798/// [[omp::for(...)]] for (...) { ... } 799/// 800class AttributedStmt : public Stmt { 801 Stmt *SubStmt; 802 SourceLocation AttrLoc; 803 unsigned NumAttrs; 804 const Attr *Attrs[1]; 805 806 friend class ASTStmtReader; 807 808 AttributedStmt(SourceLocation Loc, ArrayRef<const Attr*> Attrs, Stmt *SubStmt) 809 : Stmt(AttributedStmtClass), SubStmt(SubStmt), AttrLoc(Loc), 810 NumAttrs(Attrs.size()) { 811 memcpy(this->Attrs, Attrs.data(), Attrs.size() * sizeof(Attr*)); 812 } 813 814 explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs) 815 : Stmt(AttributedStmtClass, Empty), NumAttrs(NumAttrs) { 816 memset(Attrs, 0, NumAttrs * sizeof(Attr*)); 817 } 818 819public: 820 static AttributedStmt *Create(ASTContext &C, SourceLocation Loc, 821 ArrayRef<const Attr*> Attrs, Stmt *SubStmt); 822 // \brief Build an empty attributed statement. 823 static AttributedStmt *CreateEmpty(ASTContext &C, unsigned NumAttrs); 824 825 SourceLocation getAttrLoc() const { return AttrLoc; } 826 ArrayRef<const Attr*> getAttrs() const { 827 return ArrayRef<const Attr*>(Attrs, NumAttrs); 828 } 829 Stmt *getSubStmt() { return SubStmt; } 830 const Stmt *getSubStmt() const { return SubStmt; } 831 832 SourceRange getSourceRange() const LLVM_READONLY { 833 return SourceRange(AttrLoc, SubStmt->getLocEnd()); 834 } 835 child_range children() { return child_range(&SubStmt, &SubStmt + 1); } 836 837 static bool classof(const Stmt *T) { 838 return T->getStmtClass() == AttributedStmtClass; 839 } 840 static bool classof(const AttributedStmt *) { return true; } 841}; 842 843 844/// IfStmt - This represents an if/then/else. 845/// 846class IfStmt : public Stmt { 847 enum { VAR, COND, THEN, ELSE, END_EXPR }; 848 Stmt* SubExprs[END_EXPR]; 849 850 SourceLocation IfLoc; 851 SourceLocation ElseLoc; 852 853public: 854 IfStmt(ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond, 855 Stmt *then, SourceLocation EL = SourceLocation(), Stmt *elsev = 0); 856 857 /// \brief Build an empty if/then/else statement 858 explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { } 859 860 /// \brief Retrieve the variable declared in this "if" statement, if any. 861 /// 862 /// In the following example, "x" is the condition variable. 863 /// \code 864 /// if (int x = foo()) { 865 /// printf("x is %d", x); 866 /// } 867 /// \endcode 868 VarDecl *getConditionVariable() const; 869 void setConditionVariable(ASTContext &C, VarDecl *V); 870 871 /// If this IfStmt has a condition variable, return the faux DeclStmt 872 /// associated with the creation of that condition variable. 873 const DeclStmt *getConditionVariableDeclStmt() const { 874 return reinterpret_cast<DeclStmt*>(SubExprs[VAR]); 875 } 876 877 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 878 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); } 879 const Stmt *getThen() const { return SubExprs[THEN]; } 880 void setThen(Stmt *S) { SubExprs[THEN] = S; } 881 const Stmt *getElse() const { return SubExprs[ELSE]; } 882 void setElse(Stmt *S) { SubExprs[ELSE] = S; } 883 884 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 885 Stmt *getThen() { return SubExprs[THEN]; } 886 Stmt *getElse() { return SubExprs[ELSE]; } 887 888 SourceLocation getIfLoc() const { return IfLoc; } 889 void setIfLoc(SourceLocation L) { IfLoc = L; } 890 SourceLocation getElseLoc() const { return ElseLoc; } 891 void setElseLoc(SourceLocation L) { ElseLoc = L; } 892 893 SourceRange getSourceRange() const LLVM_READONLY { 894 if (SubExprs[ELSE]) 895 return SourceRange(IfLoc, SubExprs[ELSE]->getLocEnd()); 896 else 897 return SourceRange(IfLoc, SubExprs[THEN]->getLocEnd()); 898 } 899 900 // Iterators over subexpressions. The iterators will include iterating 901 // over the initialization expression referenced by the condition variable. 902 child_range children() { 903 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 904 } 905 906 static bool classof(const Stmt *T) { 907 return T->getStmtClass() == IfStmtClass; 908 } 909 static bool classof(const IfStmt *) { return true; } 910}; 911 912/// SwitchStmt - This represents a 'switch' stmt. 913/// 914class SwitchStmt : public Stmt { 915 enum { VAR, COND, BODY, END_EXPR }; 916 Stmt* SubExprs[END_EXPR]; 917 // This points to a linked list of case and default statements. 918 SwitchCase *FirstCase; 919 SourceLocation SwitchLoc; 920 921 /// If the SwitchStmt is a switch on an enum value, this records whether 922 /// all the enum values were covered by CaseStmts. This value is meant to 923 /// be a hint for possible clients. 924 unsigned AllEnumCasesCovered : 1; 925 926public: 927 SwitchStmt(ASTContext &C, VarDecl *Var, Expr *cond); 928 929 /// \brief Build a empty switch statement. 930 explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { } 931 932 /// \brief Retrieve the variable declared in this "switch" statement, if any. 933 /// 934 /// In the following example, "x" is the condition variable. 935 /// \code 936 /// switch (int x = foo()) { 937 /// case 0: break; 938 /// // ... 939 /// } 940 /// \endcode 941 VarDecl *getConditionVariable() const; 942 void setConditionVariable(ASTContext &C, VarDecl *V); 943 944 /// If this SwitchStmt has a condition variable, return the faux DeclStmt 945 /// associated with the creation of that condition variable. 946 const DeclStmt *getConditionVariableDeclStmt() const { 947 return reinterpret_cast<DeclStmt*>(SubExprs[VAR]); 948 } 949 950 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 951 const Stmt *getBody() const { return SubExprs[BODY]; } 952 const SwitchCase *getSwitchCaseList() const { return FirstCase; } 953 954 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);} 955 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); } 956 Stmt *getBody() { return SubExprs[BODY]; } 957 void setBody(Stmt *S) { SubExprs[BODY] = S; } 958 SwitchCase *getSwitchCaseList() { return FirstCase; } 959 960 /// \brief Set the case list for this switch statement. 961 /// 962 /// The caller is responsible for incrementing the retain counts on 963 /// all of the SwitchCase statements in this list. 964 void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; } 965 966 SourceLocation getSwitchLoc() const { return SwitchLoc; } 967 void setSwitchLoc(SourceLocation L) { SwitchLoc = L; } 968 969 void setBody(Stmt *S, SourceLocation SL) { 970 SubExprs[BODY] = S; 971 SwitchLoc = SL; 972 } 973 void addSwitchCase(SwitchCase *SC) { 974 assert(!SC->getNextSwitchCase() 975 && "case/default already added to a switch"); 976 SC->setNextSwitchCase(FirstCase); 977 FirstCase = SC; 978 } 979 980 /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a 981 /// switch over an enum value then all cases have been explicitly covered. 982 void setAllEnumCasesCovered() { 983 AllEnumCasesCovered = 1; 984 } 985 986 /// Returns true if the SwitchStmt is a switch of an enum value and all cases 987 /// have been explicitly covered. 988 bool isAllEnumCasesCovered() const { 989 return (bool) AllEnumCasesCovered; 990 } 991 992 SourceRange getSourceRange() const LLVM_READONLY { 993 return SourceRange(SwitchLoc, SubExprs[BODY]->getLocEnd()); 994 } 995 // Iterators 996 child_range children() { 997 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 998 } 999 1000 static bool classof(const Stmt *T) { 1001 return T->getStmtClass() == SwitchStmtClass; 1002 } 1003 static bool classof(const SwitchStmt *) { return true; } 1004}; 1005 1006 1007/// WhileStmt - This represents a 'while' stmt. 1008/// 1009class WhileStmt : public Stmt { 1010 enum { VAR, COND, BODY, END_EXPR }; 1011 Stmt* SubExprs[END_EXPR]; 1012 SourceLocation WhileLoc; 1013public: 1014 WhileStmt(ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body, 1015 SourceLocation WL); 1016 1017 /// \brief Build an empty while statement. 1018 explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { } 1019 1020 /// \brief Retrieve the variable declared in this "while" statement, if any. 1021 /// 1022 /// In the following example, "x" is the condition variable. 1023 /// \code 1024 /// while (int x = random()) { 1025 /// // ... 1026 /// } 1027 /// \endcode 1028 VarDecl *getConditionVariable() const; 1029 void setConditionVariable(ASTContext &C, VarDecl *V); 1030 1031 /// If this WhileStmt has a condition variable, return the faux DeclStmt 1032 /// associated with the creation of that condition variable. 1033 const DeclStmt *getConditionVariableDeclStmt() const { 1034 return reinterpret_cast<DeclStmt*>(SubExprs[VAR]); 1035 } 1036 1037 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 1038 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 1039 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 1040 Stmt *getBody() { return SubExprs[BODY]; } 1041 const Stmt *getBody() const { return SubExprs[BODY]; } 1042 void setBody(Stmt *S) { SubExprs[BODY] = S; } 1043 1044 SourceLocation getWhileLoc() const { return WhileLoc; } 1045 void setWhileLoc(SourceLocation L) { WhileLoc = L; } 1046 1047 SourceRange getSourceRange() const LLVM_READONLY { 1048 return SourceRange(WhileLoc, SubExprs[BODY]->getLocEnd()); 1049 } 1050 static bool classof(const Stmt *T) { 1051 return T->getStmtClass() == WhileStmtClass; 1052 } 1053 static bool classof(const WhileStmt *) { return true; } 1054 1055 // Iterators 1056 child_range children() { 1057 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 1058 } 1059}; 1060 1061/// DoStmt - This represents a 'do/while' stmt. 1062/// 1063class DoStmt : public Stmt { 1064 enum { BODY, COND, END_EXPR }; 1065 Stmt* SubExprs[END_EXPR]; 1066 SourceLocation DoLoc; 1067 SourceLocation WhileLoc; 1068 SourceLocation RParenLoc; // Location of final ')' in do stmt condition. 1069 1070public: 1071 DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL, 1072 SourceLocation RP) 1073 : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) { 1074 SubExprs[COND] = reinterpret_cast<Stmt*>(cond); 1075 SubExprs[BODY] = body; 1076 } 1077 1078 /// \brief Build an empty do-while statement. 1079 explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { } 1080 1081 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 1082 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 1083 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 1084 Stmt *getBody() { return SubExprs[BODY]; } 1085 const Stmt *getBody() const { return SubExprs[BODY]; } 1086 void setBody(Stmt *S) { SubExprs[BODY] = S; } 1087 1088 SourceLocation getDoLoc() const { return DoLoc; } 1089 void setDoLoc(SourceLocation L) { DoLoc = L; } 1090 SourceLocation getWhileLoc() const { return WhileLoc; } 1091 void setWhileLoc(SourceLocation L) { WhileLoc = L; } 1092 1093 SourceLocation getRParenLoc() const { return RParenLoc; } 1094 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1095 1096 SourceRange getSourceRange() const LLVM_READONLY { 1097 return SourceRange(DoLoc, RParenLoc); 1098 } 1099 static bool classof(const Stmt *T) { 1100 return T->getStmtClass() == DoStmtClass; 1101 } 1102 static bool classof(const DoStmt *) { return true; } 1103 1104 // Iterators 1105 child_range children() { 1106 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 1107 } 1108}; 1109 1110 1111/// ForStmt - This represents a 'for (init;cond;inc)' stmt. Note that any of 1112/// the init/cond/inc parts of the ForStmt will be null if they were not 1113/// specified in the source. 1114/// 1115class ForStmt : public Stmt { 1116 enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR }; 1117 Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt. 1118 SourceLocation ForLoc; 1119 SourceLocation LParenLoc, RParenLoc; 1120 1121public: 1122 ForStmt(ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, Expr *Inc, 1123 Stmt *Body, SourceLocation FL, SourceLocation LP, SourceLocation RP); 1124 1125 /// \brief Build an empty for statement. 1126 explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { } 1127 1128 Stmt *getInit() { return SubExprs[INIT]; } 1129 1130 /// \brief Retrieve the variable declared in this "for" statement, if any. 1131 /// 1132 /// In the following example, "y" is the condition variable. 1133 /// \code 1134 /// for (int x = random(); int y = mangle(x); ++x) { 1135 /// // ... 1136 /// } 1137 /// \endcode 1138 VarDecl *getConditionVariable() const; 1139 void setConditionVariable(ASTContext &C, VarDecl *V); 1140 1141 /// If this ForStmt has a condition variable, return the faux DeclStmt 1142 /// associated with the creation of that condition variable. 1143 const DeclStmt *getConditionVariableDeclStmt() const { 1144 return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]); 1145 } 1146 1147 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 1148 Expr *getInc() { return reinterpret_cast<Expr*>(SubExprs[INC]); } 1149 Stmt *getBody() { return SubExprs[BODY]; } 1150 1151 const Stmt *getInit() const { return SubExprs[INIT]; } 1152 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 1153 const Expr *getInc() const { return reinterpret_cast<Expr*>(SubExprs[INC]); } 1154 const Stmt *getBody() const { return SubExprs[BODY]; } 1155 1156 void setInit(Stmt *S) { SubExprs[INIT] = S; } 1157 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 1158 void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); } 1159 void setBody(Stmt *S) { SubExprs[BODY] = S; } 1160 1161 SourceLocation getForLoc() const { return ForLoc; } 1162 void setForLoc(SourceLocation L) { ForLoc = L; } 1163 SourceLocation getLParenLoc() const { return LParenLoc; } 1164 void setLParenLoc(SourceLocation L) { LParenLoc = L; } 1165 SourceLocation getRParenLoc() const { return RParenLoc; } 1166 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1167 1168 SourceRange getSourceRange() const LLVM_READONLY { 1169 return SourceRange(ForLoc, SubExprs[BODY]->getLocEnd()); 1170 } 1171 static bool classof(const Stmt *T) { 1172 return T->getStmtClass() == ForStmtClass; 1173 } 1174 static bool classof(const ForStmt *) { return true; } 1175 1176 // Iterators 1177 child_range children() { 1178 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); 1179 } 1180}; 1181 1182/// GotoStmt - This represents a direct goto. 1183/// 1184class GotoStmt : public Stmt { 1185 LabelDecl *Label; 1186 SourceLocation GotoLoc; 1187 SourceLocation LabelLoc; 1188public: 1189 GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL) 1190 : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {} 1191 1192 /// \brief Build an empty goto statement. 1193 explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { } 1194 1195 LabelDecl *getLabel() const { return Label; } 1196 void setLabel(LabelDecl *D) { Label = D; } 1197 1198 SourceLocation getGotoLoc() const { return GotoLoc; } 1199 void setGotoLoc(SourceLocation L) { GotoLoc = L; } 1200 SourceLocation getLabelLoc() const { return LabelLoc; } 1201 void setLabelLoc(SourceLocation L) { LabelLoc = L; } 1202 1203 SourceRange getSourceRange() const LLVM_READONLY { 1204 return SourceRange(GotoLoc, LabelLoc); 1205 } 1206 static bool classof(const Stmt *T) { 1207 return T->getStmtClass() == GotoStmtClass; 1208 } 1209 static bool classof(const GotoStmt *) { return true; } 1210 1211 // Iterators 1212 child_range children() { return child_range(); } 1213}; 1214 1215/// IndirectGotoStmt - This represents an indirect goto. 1216/// 1217class IndirectGotoStmt : public Stmt { 1218 SourceLocation GotoLoc; 1219 SourceLocation StarLoc; 1220 Stmt *Target; 1221public: 1222 IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc, 1223 Expr *target) 1224 : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc), 1225 Target((Stmt*)target) {} 1226 1227 /// \brief Build an empty indirect goto statement. 1228 explicit IndirectGotoStmt(EmptyShell Empty) 1229 : Stmt(IndirectGotoStmtClass, Empty) { } 1230 1231 void setGotoLoc(SourceLocation L) { GotoLoc = L; } 1232 SourceLocation getGotoLoc() const { return GotoLoc; } 1233 void setStarLoc(SourceLocation L) { StarLoc = L; } 1234 SourceLocation getStarLoc() const { return StarLoc; } 1235 1236 Expr *getTarget() { return reinterpret_cast<Expr*>(Target); } 1237 const Expr *getTarget() const {return reinterpret_cast<const Expr*>(Target);} 1238 void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); } 1239 1240 /// getConstantTarget - Returns the fixed target of this indirect 1241 /// goto, if one exists. 1242 LabelDecl *getConstantTarget(); 1243 const LabelDecl *getConstantTarget() const { 1244 return const_cast<IndirectGotoStmt*>(this)->getConstantTarget(); 1245 } 1246 1247 SourceRange getSourceRange() const LLVM_READONLY { 1248 return SourceRange(GotoLoc, Target->getLocEnd()); 1249 } 1250 1251 static bool classof(const Stmt *T) { 1252 return T->getStmtClass() == IndirectGotoStmtClass; 1253 } 1254 static bool classof(const IndirectGotoStmt *) { return true; } 1255 1256 // Iterators 1257 child_range children() { return child_range(&Target, &Target+1); } 1258}; 1259 1260 1261/// ContinueStmt - This represents a continue. 1262/// 1263class ContinueStmt : public Stmt { 1264 SourceLocation ContinueLoc; 1265public: 1266 ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {} 1267 1268 /// \brief Build an empty continue statement. 1269 explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { } 1270 1271 SourceLocation getContinueLoc() const { return ContinueLoc; } 1272 void setContinueLoc(SourceLocation L) { ContinueLoc = L; } 1273 1274 SourceRange getSourceRange() const LLVM_READONLY { 1275 return SourceRange(ContinueLoc); 1276 } 1277 1278 static bool classof(const Stmt *T) { 1279 return T->getStmtClass() == ContinueStmtClass; 1280 } 1281 static bool classof(const ContinueStmt *) { return true; } 1282 1283 // Iterators 1284 child_range children() { return child_range(); } 1285}; 1286 1287/// BreakStmt - This represents a break. 1288/// 1289class BreakStmt : public Stmt { 1290 SourceLocation BreakLoc; 1291public: 1292 BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {} 1293 1294 /// \brief Build an empty break statement. 1295 explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { } 1296 1297 SourceLocation getBreakLoc() const { return BreakLoc; } 1298 void setBreakLoc(SourceLocation L) { BreakLoc = L; } 1299 1300 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(BreakLoc); } 1301 1302 static bool classof(const Stmt *T) { 1303 return T->getStmtClass() == BreakStmtClass; 1304 } 1305 static bool classof(const BreakStmt *) { return true; } 1306 1307 // Iterators 1308 child_range children() { return child_range(); } 1309}; 1310 1311 1312/// ReturnStmt - This represents a return, optionally of an expression: 1313/// return; 1314/// return 4; 1315/// 1316/// Note that GCC allows return with no argument in a function declared to 1317/// return a value, and it allows returning a value in functions declared to 1318/// return void. We explicitly model this in the AST, which means you can't 1319/// depend on the return type of the function and the presence of an argument. 1320/// 1321class ReturnStmt : public Stmt { 1322 Stmt *RetExpr; 1323 SourceLocation RetLoc; 1324 const VarDecl *NRVOCandidate; 1325 1326public: 1327 ReturnStmt(SourceLocation RL) 1328 : Stmt(ReturnStmtClass), RetExpr(0), RetLoc(RL), NRVOCandidate(0) { } 1329 1330 ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate) 1331 : Stmt(ReturnStmtClass), RetExpr((Stmt*) E), RetLoc(RL), 1332 NRVOCandidate(NRVOCandidate) {} 1333 1334 /// \brief Build an empty return expression. 1335 explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { } 1336 1337 const Expr *getRetValue() const; 1338 Expr *getRetValue(); 1339 void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); } 1340 1341 SourceLocation getReturnLoc() const { return RetLoc; } 1342 void setReturnLoc(SourceLocation L) { RetLoc = L; } 1343 1344 /// \brief Retrieve the variable that might be used for the named return 1345 /// value optimization. 1346 /// 1347 /// The optimization itself can only be performed if the variable is 1348 /// also marked as an NRVO object. 1349 const VarDecl *getNRVOCandidate() const { return NRVOCandidate; } 1350 void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; } 1351 1352 SourceRange getSourceRange() const LLVM_READONLY; 1353 1354 static bool classof(const Stmt *T) { 1355 return T->getStmtClass() == ReturnStmtClass; 1356 } 1357 static bool classof(const ReturnStmt *) { return true; } 1358 1359 // Iterators 1360 child_range children() { 1361 if (RetExpr) return child_range(&RetExpr, &RetExpr+1); 1362 return child_range(); 1363 } 1364}; 1365 1366/// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt. 1367/// 1368class AsmStmt : public Stmt { 1369protected: 1370 SourceLocation AsmLoc; 1371 /// \brief True if the assembly statement does not have any input or output 1372 /// operands. 1373 bool IsSimple; 1374 1375 /// \brief If true, treat this inline assembly as having side effects. 1376 /// This assembly statement should not be optimized, deleted or moved. 1377 bool IsVolatile; 1378 1379 unsigned NumOutputs; 1380 unsigned NumInputs; 1381 unsigned NumClobbers; 1382 1383 IdentifierInfo **Names; 1384 Stmt **Exprs; 1385 1386 AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile, 1387 unsigned numoutputs, unsigned numinputs, unsigned numclobbers) : 1388 Stmt (SC), AsmLoc(asmloc), IsSimple(issimple), IsVolatile(isvolatile), 1389 NumOutputs(numoutputs), NumInputs(numinputs), NumClobbers(numclobbers) { } 1390 1391public: 1392 /// \brief Build an empty inline-assembly statement. 1393 explicit AsmStmt(StmtClass SC, EmptyShell Empty) : 1394 Stmt(SC, Empty), Names(0), Exprs(0) { } 1395 1396 SourceLocation getAsmLoc() const { return AsmLoc; } 1397 void setAsmLoc(SourceLocation L) { AsmLoc = L; } 1398 1399 bool isSimple() const { return IsSimple; } 1400 void setSimple(bool V) { IsSimple = V; } 1401 1402 bool isVolatile() const { return IsVolatile; } 1403 void setVolatile(bool V) { IsVolatile = V; } 1404 1405 SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(); } 1406 1407 //===--- Asm String Analysis ---===// 1408 1409 /// Assemble final IR asm string. 1410 virtual std::string generateAsmString(ASTContext &C) const = 0; 1411 1412 //===--- Output operands ---===// 1413 1414 unsigned getNumOutputs() const { return NumOutputs; } 1415 1416 IdentifierInfo *getOutputIdentifier(unsigned i) const { 1417 return Names[i]; 1418 } 1419 1420 StringRef getOutputName(unsigned i) const { 1421 if (IdentifierInfo *II = getOutputIdentifier(i)) 1422 return II->getName(); 1423 1424 return StringRef(); 1425 } 1426 1427 //===--- Input operands ---===// 1428 1429 unsigned getNumInputs() const { return NumInputs; } 1430 1431 IdentifierInfo *getInputIdentifier(unsigned i) const { 1432 return Names[i + NumOutputs]; 1433 } 1434 1435 StringRef getInputName(unsigned i) const { 1436 if (IdentifierInfo *II = getInputIdentifier(i)) 1437 return II->getName(); 1438 1439 return StringRef(); 1440 } 1441 1442 //===--- Other ---===// 1443 1444 static bool classof(const Stmt *T) { 1445 return T->getStmtClass() == GCCAsmStmtClass || 1446 T->getStmtClass() == MSAsmStmtClass; 1447 } 1448 static bool classof(const AsmStmt *) { return true; } 1449 1450 // Input expr iterators. 1451 1452 typedef ExprIterator inputs_iterator; 1453 typedef ConstExprIterator const_inputs_iterator; 1454 1455 inputs_iterator begin_inputs() { 1456 return &Exprs[0] + NumOutputs; 1457 } 1458 1459 inputs_iterator end_inputs() { 1460 return &Exprs[0] + NumOutputs + NumInputs; 1461 } 1462 1463 const_inputs_iterator begin_inputs() const { 1464 return &Exprs[0] + NumOutputs; 1465 } 1466 1467 const_inputs_iterator end_inputs() const { 1468 return &Exprs[0] + NumOutputs + NumInputs; 1469 } 1470 1471 // Output expr iterators. 1472 1473 typedef ExprIterator outputs_iterator; 1474 typedef ConstExprIterator const_outputs_iterator; 1475 1476 outputs_iterator begin_outputs() { 1477 return &Exprs[0]; 1478 } 1479 outputs_iterator end_outputs() { 1480 return &Exprs[0] + NumOutputs; 1481 } 1482 1483 const_outputs_iterator begin_outputs() const { 1484 return &Exprs[0]; 1485 } 1486 const_outputs_iterator end_outputs() const { 1487 return &Exprs[0] + NumOutputs; 1488 } 1489 1490 child_range children() { 1491 return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs); 1492 } 1493}; 1494 1495/// This represents a GCC inline-assembly statement extension. 1496/// 1497class GCCAsmStmt : public AsmStmt { 1498 SourceLocation RParenLoc; 1499 StringLiteral *AsmStr; 1500 1501 // FIXME: If we wanted to, we could allocate all of these in one big array. 1502 StringLiteral **Constraints; 1503 StringLiteral **Clobbers; 1504 1505public: 1506 GCCAsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple, 1507 bool isvolatile, unsigned numoutputs, unsigned numinputs, 1508 IdentifierInfo **names, StringLiteral **constraints, Expr **exprs, 1509 StringLiteral *asmstr, unsigned numclobbers, 1510 StringLiteral **clobbers, SourceLocation rparenloc); 1511 1512 /// \brief Build an empty inline-assembly statement. 1513 explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty), 1514 Constraints(0), Clobbers(0) { } 1515 1516 SourceLocation getRParenLoc() const { return RParenLoc; } 1517 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1518 1519 //===--- Asm String Analysis ---===// 1520 1521 const StringLiteral *getAsmString() const { return AsmStr; } 1522 StringLiteral *getAsmString() { return AsmStr; } 1523 void setAsmString(StringLiteral *E) { AsmStr = E; } 1524 1525 /// AsmStringPiece - this is part of a decomposed asm string specification 1526 /// (for use with the AnalyzeAsmString function below). An asm string is 1527 /// considered to be a concatenation of these parts. 1528 class AsmStringPiece { 1529 public: 1530 enum Kind { 1531 String, // String in .ll asm string form, "$" -> "$$" and "%%" -> "%". 1532 Operand // Operand reference, with optional modifier %c4. 1533 }; 1534 private: 1535 Kind MyKind; 1536 std::string Str; 1537 unsigned OperandNo; 1538 public: 1539 AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {} 1540 AsmStringPiece(unsigned OpNo, char Modifier) 1541 : MyKind(Operand), Str(), OperandNo(OpNo) { 1542 Str += Modifier; 1543 } 1544 1545 bool isString() const { return MyKind == String; } 1546 bool isOperand() const { return MyKind == Operand; } 1547 1548 const std::string &getString() const { 1549 assert(isString()); 1550 return Str; 1551 } 1552 1553 unsigned getOperandNo() const { 1554 assert(isOperand()); 1555 return OperandNo; 1556 } 1557 1558 /// getModifier - Get the modifier for this operand, if present. This 1559 /// returns '\0' if there was no modifier. 1560 char getModifier() const { 1561 assert(isOperand()); 1562 return Str[0]; 1563 } 1564 }; 1565 1566 /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing 1567 /// it into pieces. If the asm string is erroneous, emit errors and return 1568 /// true, otherwise return false. This handles canonicalization and 1569 /// translation of strings from GCC syntax to LLVM IR syntax, and handles 1570 //// flattening of named references like %[foo] to Operand AsmStringPiece's. 1571 unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces, 1572 ASTContext &C, unsigned &DiagOffs) const; 1573 1574 /// Assemble final IR asm string. 1575 std::string generateAsmString(ASTContext &C) const; 1576 1577 //===--- Output operands ---===// 1578 1579 /// getOutputConstraint - Return the constraint string for the specified 1580 /// output operand. All output constraints are known to be non-empty (either 1581 /// '=' or '+'). 1582 StringRef getOutputConstraint(unsigned i) const; 1583 1584 const StringLiteral *getOutputConstraintLiteral(unsigned i) const { 1585 return Constraints[i]; 1586 } 1587 StringLiteral *getOutputConstraintLiteral(unsigned i) { 1588 return Constraints[i]; 1589 } 1590 1591 Expr *getOutputExpr(unsigned i); 1592 1593 const Expr *getOutputExpr(unsigned i) const { 1594 return const_cast<GCCAsmStmt*>(this)->getOutputExpr(i); 1595 } 1596 1597 /// isOutputPlusConstraint - Return true if the specified output constraint 1598 /// is a "+" constraint (which is both an input and an output) or false if it 1599 /// is an "=" constraint (just an output). 1600 bool isOutputPlusConstraint(unsigned i) const { 1601 return getOutputConstraint(i)[0] == '+'; 1602 } 1603 1604 /// getNumPlusOperands - Return the number of output operands that have a "+" 1605 /// constraint. 1606 unsigned getNumPlusOperands() const; 1607 1608 //===--- Input operands ---===// 1609 1610 /// getInputConstraint - Return the specified input constraint. Unlike output 1611 /// constraints, these can be empty. 1612 StringRef getInputConstraint(unsigned i) const; 1613 1614 const StringLiteral *getInputConstraintLiteral(unsigned i) const { 1615 return Constraints[i + NumOutputs]; 1616 } 1617 StringLiteral *getInputConstraintLiteral(unsigned i) { 1618 return Constraints[i + NumOutputs]; 1619 } 1620 1621 Expr *getInputExpr(unsigned i); 1622 void setInputExpr(unsigned i, Expr *E); 1623 1624 const Expr *getInputExpr(unsigned i) const { 1625 return const_cast<GCCAsmStmt*>(this)->getInputExpr(i); 1626 } 1627 1628 void setOutputsAndInputsAndClobbers(ASTContext &C, 1629 IdentifierInfo **Names, 1630 StringLiteral **Constraints, 1631 Stmt **Exprs, 1632 unsigned NumOutputs, 1633 unsigned NumInputs, 1634 StringLiteral **Clobbers, 1635 unsigned NumClobbers); 1636 1637 //===--- Other ---===// 1638 1639 /// getNamedOperand - Given a symbolic operand reference like %[foo], 1640 /// translate this into a numeric value needed to reference the same operand. 1641 /// This returns -1 if the operand name is invalid. 1642 int getNamedOperand(StringRef SymbolicName) const; 1643 1644 unsigned getNumClobbers() const { return NumClobbers; } 1645 StringLiteral *getClobber(unsigned i) { return Clobbers[i]; } 1646 const StringLiteral *getClobber(unsigned i) const { return Clobbers[i]; } 1647 1648 SourceRange getSourceRange() const LLVM_READONLY { 1649 return SourceRange(AsmLoc, RParenLoc); 1650 } 1651 1652 static bool classof(const Stmt *T) { 1653 return T->getStmtClass() == GCCAsmStmtClass; 1654 } 1655 static bool classof(const GCCAsmStmt *) { return true; } 1656}; 1657 1658/// This represents a Microsoft inline-assembly statement extension. 1659/// 1660class MSAsmStmt : public AsmStmt { 1661 SourceLocation AsmLoc, LBraceLoc, EndLoc; 1662 std::string AsmStr; 1663 1664 unsigned NumAsmToks; 1665 1666 Token *AsmToks; 1667 StringRef *Clobbers; 1668 1669public: 1670 MSAsmStmt(ASTContext &C, SourceLocation asmloc, SourceLocation lbraceloc, 1671 bool issimple, bool isvolatile, ArrayRef<Token> asmtoks, 1672 ArrayRef<IdentifierInfo*> inputs, ArrayRef<IdentifierInfo*> outputs, 1673 ArrayRef<Expr*> inputexprs, ArrayRef<Expr*> outputexprs, 1674 StringRef asmstr, ArrayRef<StringRef> clobbers, 1675 SourceLocation endloc); 1676 1677 /// \brief Build an empty MS-style inline-assembly statement. 1678 explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty), 1679 NumAsmToks(0), AsmToks(0), Clobbers(0) { } 1680 1681 SourceLocation getLBraceLoc() const { return LBraceLoc; } 1682 void setLBraceLoc(SourceLocation L) { LBraceLoc = L; } 1683 SourceLocation getEndLoc() const { return EndLoc; } 1684 void setEndLoc(SourceLocation L) { EndLoc = L; } 1685 1686 bool hasBraces() const { return LBraceLoc.isValid(); } 1687 1688 unsigned getNumAsmToks() { return NumAsmToks; } 1689 Token *getAsmToks() { return AsmToks; } 1690 1691 //===--- Asm String Analysis ---===// 1692 1693 const std::string *getAsmString() const { return &AsmStr; } 1694 std::string *getAsmString() { return &AsmStr; } 1695 void setAsmString(StringRef &E) { AsmStr = E.str(); } 1696 1697 /// Assemble final IR asm string. 1698 std::string generateAsmString(ASTContext &C) const; 1699 1700 //===--- Output operands ---===// 1701 1702 Expr *getOutputExpr(unsigned i); 1703 1704 const Expr *getOutputExpr(unsigned i) const { 1705 return const_cast<MSAsmStmt*>(this)->getOutputExpr(i); 1706 } 1707 1708 //===--- Input operands ---===// 1709 1710 Expr *getInputExpr(unsigned i); 1711 void setInputExpr(unsigned i, Expr *E); 1712 1713 const Expr *getInputExpr(unsigned i) const { 1714 return const_cast<MSAsmStmt*>(this)->getInputExpr(i); 1715 } 1716 1717 //===--- Other ---===// 1718 1719 unsigned getNumClobbers() const { return NumClobbers; } 1720 StringRef getClobber(unsigned i) const { return Clobbers[i]; } 1721 1722 SourceRange getSourceRange() const LLVM_READONLY { 1723 return SourceRange(AsmLoc, EndLoc); 1724 } 1725 static bool classof(const Stmt *T) { 1726 return T->getStmtClass() == MSAsmStmtClass; 1727 } 1728 static bool classof(const MSAsmStmt *) { return true; } 1729 1730 child_range children() { 1731 return child_range(&Exprs[0], &Exprs[0]); 1732 } 1733}; 1734 1735class SEHExceptStmt : public Stmt { 1736 SourceLocation Loc; 1737 Stmt *Children[2]; 1738 1739 enum { FILTER_EXPR, BLOCK }; 1740 1741 SEHExceptStmt(SourceLocation Loc, 1742 Expr *FilterExpr, 1743 Stmt *Block); 1744 1745 friend class ASTReader; 1746 friend class ASTStmtReader; 1747 explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) { } 1748 1749public: 1750 static SEHExceptStmt* Create(ASTContext &C, 1751 SourceLocation ExceptLoc, 1752 Expr *FilterExpr, 1753 Stmt *Block); 1754 SourceRange getSourceRange() const LLVM_READONLY { 1755 return SourceRange(getExceptLoc(), getEndLoc()); 1756 } 1757 1758 SourceLocation getExceptLoc() const { return Loc; } 1759 SourceLocation getEndLoc() const { return getBlock()->getLocEnd(); } 1760 1761 Expr *getFilterExpr() const { 1762 return reinterpret_cast<Expr*>(Children[FILTER_EXPR]); 1763 } 1764 1765 CompoundStmt *getBlock() const { 1766 return llvm::cast<CompoundStmt>(Children[BLOCK]); 1767 } 1768 1769 child_range children() { 1770 return child_range(Children,Children+2); 1771 } 1772 1773 static bool classof(const Stmt *T) { 1774 return T->getStmtClass() == SEHExceptStmtClass; 1775 } 1776 1777 static bool classof(SEHExceptStmt *) { return true; } 1778 1779}; 1780 1781class SEHFinallyStmt : public Stmt { 1782 SourceLocation Loc; 1783 Stmt *Block; 1784 1785 SEHFinallyStmt(SourceLocation Loc, 1786 Stmt *Block); 1787 1788 friend class ASTReader; 1789 friend class ASTStmtReader; 1790 explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) { } 1791 1792public: 1793 static SEHFinallyStmt* Create(ASTContext &C, 1794 SourceLocation FinallyLoc, 1795 Stmt *Block); 1796 1797 SourceRange getSourceRange() const LLVM_READONLY { 1798 return SourceRange(getFinallyLoc(), getEndLoc()); 1799 } 1800 1801 SourceLocation getFinallyLoc() const { return Loc; } 1802 SourceLocation getEndLoc() const { return Block->getLocEnd(); } 1803 1804 CompoundStmt *getBlock() const { return llvm::cast<CompoundStmt>(Block); } 1805 1806 child_range children() { 1807 return child_range(&Block,&Block+1); 1808 } 1809 1810 static bool classof(const Stmt *T) { 1811 return T->getStmtClass() == SEHFinallyStmtClass; 1812 } 1813 1814 static bool classof(SEHFinallyStmt *) { return true; } 1815 1816}; 1817 1818class SEHTryStmt : public Stmt { 1819 bool IsCXXTry; 1820 SourceLocation TryLoc; 1821 Stmt *Children[2]; 1822 1823 enum { TRY = 0, HANDLER = 1 }; 1824 1825 SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try' 1826 SourceLocation TryLoc, 1827 Stmt *TryBlock, 1828 Stmt *Handler); 1829 1830 friend class ASTReader; 1831 friend class ASTStmtReader; 1832 explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) { } 1833 1834public: 1835 static SEHTryStmt* Create(ASTContext &C, 1836 bool isCXXTry, 1837 SourceLocation TryLoc, 1838 Stmt *TryBlock, 1839 Stmt *Handler); 1840 1841 SourceRange getSourceRange() const LLVM_READONLY { 1842 return SourceRange(getTryLoc(), getEndLoc()); 1843 } 1844 1845 SourceLocation getTryLoc() const { return TryLoc; } 1846 SourceLocation getEndLoc() const { return Children[HANDLER]->getLocEnd(); } 1847 1848 bool getIsCXXTry() const { return IsCXXTry; } 1849 1850 CompoundStmt* getTryBlock() const { 1851 return llvm::cast<CompoundStmt>(Children[TRY]); 1852 } 1853 1854 Stmt *getHandler() const { return Children[HANDLER]; } 1855 1856 /// Returns 0 if not defined 1857 SEHExceptStmt *getExceptHandler() const; 1858 SEHFinallyStmt *getFinallyHandler() const; 1859 1860 child_range children() { 1861 return child_range(Children,Children+2); 1862 } 1863 1864 static bool classof(const Stmt *T) { 1865 return T->getStmtClass() == SEHTryStmtClass; 1866 } 1867 1868 static bool classof(SEHTryStmt *) { return true; } 1869}; 1870 1871} // end namespace clang 1872 1873#endif 1874