Stmt.h revision b2f81cf7f8445e0c65c0428f4fbb0442566916b8
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 "llvm/Support/Casting.h" 18#include "llvm/Support/raw_ostream.h" 19#include "clang/Basic/SourceLocation.h" 20#include "clang/AST/PrettyPrinter.h" 21#include "clang/AST/StmtIterator.h" 22#include "clang/AST/DeclGroup.h" 23#include "llvm/ADT/SmallVector.h" 24#include "clang/AST/ASTContext.h" 25#include <string> 26using llvm::dyn_cast_or_null; 27 28namespace llvm { 29 class FoldingSetNodeID; 30} 31 32namespace clang { 33 class ASTContext; 34 class Expr; 35 class Decl; 36 class ParmVarDecl; 37 class QualType; 38 class IdentifierInfo; 39 class SourceManager; 40 class StringLiteral; 41 class SwitchStmt; 42 43 //===----------------------------------------------------------------------===// 44 // ExprIterator - Iterators for iterating over Stmt* arrays that contain 45 // only Expr*. This is needed because AST nodes use Stmt* arrays to store 46 // references to children (to be compatible with StmtIterator). 47 //===----------------------------------------------------------------------===// 48 49 class Stmt; 50 class Expr; 51 52 class ExprIterator { 53 Stmt** I; 54 public: 55 ExprIterator(Stmt** i) : I(i) {} 56 ExprIterator() : I(0) {} 57 ExprIterator& operator++() { ++I; return *this; } 58 ExprIterator operator-(size_t i) { return I-i; } 59 ExprIterator operator+(size_t i) { return I+i; } 60 Expr* operator[](size_t idx); 61 // FIXME: Verify that this will correctly return a signed distance. 62 signed operator-(const ExprIterator& R) const { return I - R.I; } 63 Expr* operator*() const; 64 Expr* operator->() const; 65 bool operator==(const ExprIterator& R) const { return I == R.I; } 66 bool operator!=(const ExprIterator& R) const { return I != R.I; } 67 bool operator>(const ExprIterator& R) const { return I > R.I; } 68 bool operator>=(const ExprIterator& R) const { return I >= R.I; } 69 }; 70 71 class ConstExprIterator { 72 Stmt* const * I; 73 public: 74 ConstExprIterator(Stmt* const* i) : I(i) {} 75 ConstExprIterator() : I(0) {} 76 ConstExprIterator& operator++() { ++I; return *this; } 77 ConstExprIterator operator+(size_t i) { return I+i; } 78 ConstExprIterator operator-(size_t i) { return I-i; } 79 const Expr * operator[](size_t idx) const; 80 signed operator-(const ConstExprIterator& R) const { return I - R.I; } 81 const Expr * operator*() const; 82 const Expr * operator->() const; 83 bool operator==(const ConstExprIterator& R) const { return I == R.I; } 84 bool operator!=(const ConstExprIterator& R) const { return I != R.I; } 85 bool operator>(const ConstExprIterator& R) const { return I > R.I; } 86 bool operator>=(const ConstExprIterator& R) const { return I >= R.I; } 87 }; 88 89//===----------------------------------------------------------------------===// 90// AST classes for statements. 91//===----------------------------------------------------------------------===// 92 93/// Stmt - This represents one statement. 94/// 95class Stmt { 96public: 97 enum StmtClass { 98 NoStmtClass = 0, 99#define STMT(CLASS, PARENT) CLASS##Class, 100#define FIRST_STMT(CLASS) firstStmtConstant = CLASS##Class, 101#define LAST_STMT(CLASS) lastStmtConstant = CLASS##Class, 102#define FIRST_EXPR(CLASS) firstExprConstant = CLASS##Class, 103#define LAST_EXPR(CLASS) lastExprConstant = CLASS##Class 104#include "clang/AST/StmtNodes.def" 105}; 106private: 107 /// \brief The statement class. 108 const unsigned sClass : 8; 109 110 /// \brief The reference count for this statement. 111 unsigned RefCount : 24; 112 113 // Make vanilla 'new' and 'delete' illegal for Stmts. 114protected: 115 void* operator new(size_t bytes) throw() { 116 assert(0 && "Stmts cannot be allocated with regular 'new'."); 117 return 0; 118 } 119 void operator delete(void* data) throw() { 120 assert(0 && "Stmts cannot be released with regular 'delete'."); 121 } 122 123public: 124 // Only allow allocation of Stmts using the allocator in ASTContext 125 // or by doing a placement new. 126 void* operator new(size_t bytes, ASTContext& C, 127 unsigned alignment = 16) throw() { 128 return ::operator new(bytes, C, alignment); 129 } 130 131 void* operator new(size_t bytes, ASTContext* C, 132 unsigned alignment = 16) throw() { 133 return ::operator new(bytes, *C, alignment); 134 } 135 136 void* operator new(size_t bytes, void* mem) throw() { 137 return mem; 138 } 139 140 void operator delete(void*, ASTContext&, unsigned) throw() { } 141 void operator delete(void*, ASTContext*, unsigned) throw() { } 142 void operator delete(void*, std::size_t) throw() { } 143 void operator delete(void*, void*) throw() { } 144 145public: 146 /// \brief A placeholder type used to construct an empty shell of a 147 /// type, that will be filled in later (e.g., by some 148 /// de-serialization). 149 struct EmptyShell { }; 150 151protected: 152 /// DestroyChildren - Invoked by destructors of subclasses of Stmt to 153 /// recursively release child AST nodes. 154 void DestroyChildren(ASTContext& Ctx); 155 156 /// \brief Construct an empty statement. 157 explicit Stmt(StmtClass SC, EmptyShell) : sClass(SC), RefCount(1) { 158 if (Stmt::CollectingStats()) Stmt::addStmtClass(SC); 159 } 160 161 /// \brief Virtual method that performs the actual destruction of 162 /// this statement. 163 /// 164 /// Subclasses should override this method (not Destroy()) to 165 /// provide class-specific destruction. 166 virtual void DoDestroy(ASTContext &Ctx); 167 168public: 169 Stmt(StmtClass SC) : sClass(SC), RefCount(1) { 170 if (Stmt::CollectingStats()) Stmt::addStmtClass(SC); 171 } 172 virtual ~Stmt() {} 173 174 /// \brief Destroy the current statement and its children. 175 void Destroy(ASTContext &Ctx) { 176 assert(RefCount >= 1); 177 if (--RefCount == 0) 178 DoDestroy(Ctx); 179 } 180 181 /// \brief Increases the reference count for this statement. 182 /// 183 /// Invoke the Retain() operation when this statement or expression 184 /// is being shared by another owner. 185 Stmt *Retain() { 186 assert(RefCount >= 1); 187 ++RefCount; 188 return this; 189 } 190 191 StmtClass getStmtClass() const { 192 assert(RefCount >= 1 && "Referencing already-destroyed statement!"); 193 return (StmtClass)sClass; 194 } 195 const char *getStmtClassName() const; 196 197 /// SourceLocation tokens are not useful in isolation - they are low level 198 /// value objects created/interpreted by SourceManager. We assume AST 199 /// clients will have a pointer to the respective SourceManager. 200 virtual SourceRange getSourceRange() const = 0; 201 SourceLocation getLocStart() const { return getSourceRange().getBegin(); } 202 SourceLocation getLocEnd() const { return getSourceRange().getEnd(); } 203 204 // global temp stats (until we have a per-module visitor) 205 static void addStmtClass(const StmtClass s); 206 static bool CollectingStats(bool enable=false); 207 static void PrintStats(); 208 209 /// dump - This does a local dump of the specified AST fragment. It dumps the 210 /// specified node and a few nodes underneath it, but not the whole subtree. 211 /// This is useful in a debugger. 212 void dump() const; 213 void dump(SourceManager &SM) const; 214 215 /// dumpAll - This does a dump of the specified AST fragment and all subtrees. 216 void dumpAll() const; 217 void dumpAll(SourceManager &SM) const; 218 219 /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST 220 /// back to its original source language syntax. 221 void dumpPretty(ASTContext& Context) const; 222 void printPretty(llvm::raw_ostream &OS, PrinterHelper *Helper, 223 const PrintingPolicy &Policy, 224 unsigned Indentation = 0) const { 225 printPretty(OS, *(ASTContext*)0, Helper, Policy, Indentation); 226 } 227 void printPretty(llvm::raw_ostream &OS, ASTContext &Context, 228 PrinterHelper *Helper, 229 const PrintingPolicy &Policy, 230 unsigned Indentation = 0) const; 231 232 /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz. Only 233 /// works on systems with GraphViz (Mac OS X) or dot+gv installed. 234 void viewAST() const; 235 236 // Implement isa<T> support. 237 static bool classof(const Stmt *) { return true; } 238 239 /// hasImplicitControlFlow - Some statements (e.g. short circuited operations) 240 /// contain implicit control-flow in the order their subexpressions 241 /// are evaluated. This predicate returns true if this statement has 242 /// such implicit control-flow. Such statements are also specially handled 243 /// within CFGs. 244 bool hasImplicitControlFlow() const; 245 246 /// Child Iterators: All subclasses must implement child_begin and child_end 247 /// to permit easy iteration over the substatements/subexpessions of an 248 /// AST node. This permits easy iteration over all nodes in the AST. 249 typedef StmtIterator child_iterator; 250 typedef ConstStmtIterator const_child_iterator; 251 252 virtual child_iterator child_begin() = 0; 253 virtual child_iterator child_end() = 0; 254 255 const_child_iterator child_begin() const { 256 return const_child_iterator(const_cast<Stmt*>(this)->child_begin()); 257 } 258 259 const_child_iterator child_end() const { 260 return const_child_iterator(const_cast<Stmt*>(this)->child_end()); 261 } 262 263 /// \brief Produce a unique representation of the given statement. 264 /// 265 /// \brief ID once the profiling operation is complete, will contain 266 /// the unique representation of the given statement. 267 /// 268 /// \brief Context the AST context in which the statement resides 269 /// 270 /// \brief Canonical whether the profile should be based on the canonical 271 /// representation of this statement (e.g., where non-type template 272 /// parameters are identified by index/level rather than their 273 /// declaration pointers) or the exact representation of the statement as 274 /// written in the source. 275 void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context, 276 bool Canonical); 277}; 278 279/// DeclStmt - Adaptor class for mixing declarations with statements and 280/// expressions. For example, CompoundStmt mixes statements, expressions 281/// and declarations (variables, types). Another example is ForStmt, where 282/// the first statement can be an expression or a declaration. 283/// 284class DeclStmt : public Stmt { 285 DeclGroupRef DG; 286 SourceLocation StartLoc, EndLoc; 287 288public: 289 DeclStmt(DeclGroupRef dg, SourceLocation startLoc, 290 SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg), 291 StartLoc(startLoc), EndLoc(endLoc) {} 292 293 /// \brief Build an empty declaration statement. 294 explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { } 295 296 /// isSingleDecl - This method returns true if this DeclStmt refers 297 /// to a single Decl. 298 bool isSingleDecl() const { 299 return DG.isSingleDecl(); 300 } 301 302 const Decl *getSingleDecl() const { return DG.getSingleDecl(); } 303 Decl *getSingleDecl() { return DG.getSingleDecl(); } 304 305 const DeclGroupRef getDeclGroup() const { return DG; } 306 DeclGroupRef getDeclGroup() { return DG; } 307 void setDeclGroup(DeclGroupRef DGR) { DG = DGR; } 308 309 SourceLocation getStartLoc() const { return StartLoc; } 310 void setStartLoc(SourceLocation L) { StartLoc = L; } 311 SourceLocation getEndLoc() const { return EndLoc; } 312 void setEndLoc(SourceLocation L) { EndLoc = L; } 313 314 SourceRange getSourceRange() const { 315 return SourceRange(StartLoc, EndLoc); 316 } 317 318 static bool classof(const Stmt *T) { 319 return T->getStmtClass() == DeclStmtClass; 320 } 321 static bool classof(const DeclStmt *) { return true; } 322 323 // Iterators over subexpressions. 324 virtual child_iterator child_begin(); 325 virtual child_iterator child_end(); 326 327 typedef DeclGroupRef::iterator decl_iterator; 328 typedef DeclGroupRef::const_iterator const_decl_iterator; 329 330 decl_iterator decl_begin() { return DG.begin(); } 331 decl_iterator decl_end() { return DG.end(); } 332 const_decl_iterator decl_begin() const { return DG.begin(); } 333 const_decl_iterator decl_end() const { return DG.end(); } 334}; 335 336/// NullStmt - This is the null statement ";": C99 6.8.3p3. 337/// 338class NullStmt : public Stmt { 339 SourceLocation SemiLoc; 340public: 341 NullStmt(SourceLocation L) : Stmt(NullStmtClass), SemiLoc(L) {} 342 343 /// \brief Build an empty null statement. 344 explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty) { } 345 346 SourceLocation getSemiLoc() const { return SemiLoc; } 347 void setSemiLoc(SourceLocation L) { SemiLoc = L; } 348 349 virtual SourceRange getSourceRange() const { return SourceRange(SemiLoc); } 350 351 static bool classof(const Stmt *T) { 352 return T->getStmtClass() == NullStmtClass; 353 } 354 static bool classof(const NullStmt *) { return true; } 355 356 // Iterators 357 virtual child_iterator child_begin(); 358 virtual child_iterator child_end(); 359}; 360 361/// CompoundStmt - This represents a group of statements like { stmt stmt }. 362/// 363class CompoundStmt : public Stmt { 364 Stmt** Body; 365 unsigned NumStmts; 366 SourceLocation LBracLoc, RBracLoc; 367public: 368 CompoundStmt(ASTContext& C, Stmt **StmtStart, unsigned numStmts, 369 SourceLocation LB, SourceLocation RB) 370 : Stmt(CompoundStmtClass), NumStmts(numStmts), LBracLoc(LB), RBracLoc(RB) { 371 if (NumStmts == 0) { 372 Body = 0; 373 return; 374 } 375 376 Body = new (C) Stmt*[NumStmts]; 377 memcpy(Body, StmtStart, numStmts * sizeof(*Body)); 378 } 379 380 // \brief Build an empty compound statement. 381 explicit CompoundStmt(EmptyShell Empty) 382 : Stmt(CompoundStmtClass, Empty), Body(0), NumStmts(0) { } 383 384 void setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts); 385 386 bool body_empty() const { return NumStmts == 0; } 387 unsigned size() const { return NumStmts; } 388 389 typedef Stmt** body_iterator; 390 body_iterator body_begin() { return Body; } 391 body_iterator body_end() { return Body + NumStmts; } 392 Stmt *body_back() { return NumStmts ? Body[NumStmts-1] : 0; } 393 394 typedef Stmt* const * const_body_iterator; 395 const_body_iterator body_begin() const { return Body; } 396 const_body_iterator body_end() const { return Body + NumStmts; } 397 const Stmt *body_back() const { return NumStmts ? Body[NumStmts-1] : 0; } 398 399 typedef std::reverse_iterator<body_iterator> reverse_body_iterator; 400 reverse_body_iterator body_rbegin() { 401 return reverse_body_iterator(body_end()); 402 } 403 reverse_body_iterator body_rend() { 404 return reverse_body_iterator(body_begin()); 405 } 406 407 typedef std::reverse_iterator<const_body_iterator> 408 const_reverse_body_iterator; 409 410 const_reverse_body_iterator body_rbegin() const { 411 return const_reverse_body_iterator(body_end()); 412 } 413 414 const_reverse_body_iterator body_rend() const { 415 return const_reverse_body_iterator(body_begin()); 416 } 417 418 virtual SourceRange getSourceRange() const { 419 return SourceRange(LBracLoc, RBracLoc); 420 } 421 422 SourceLocation getLBracLoc() const { return LBracLoc; } 423 void setLBracLoc(SourceLocation L) { LBracLoc = L; } 424 SourceLocation getRBracLoc() const { return RBracLoc; } 425 void setRBracLoc(SourceLocation L) { RBracLoc = L; } 426 427 static bool classof(const Stmt *T) { 428 return T->getStmtClass() == CompoundStmtClass; 429 } 430 static bool classof(const CompoundStmt *) { return true; } 431 432 // Iterators 433 virtual child_iterator child_begin(); 434 virtual child_iterator child_end(); 435}; 436 437// SwitchCase is the base class for CaseStmt and DefaultStmt, 438class SwitchCase : public Stmt { 439protected: 440 // A pointer to the following CaseStmt or DefaultStmt class, 441 // used by SwitchStmt. 442 SwitchCase *NextSwitchCase; 443 444 SwitchCase(StmtClass SC) : Stmt(SC), NextSwitchCase(0) {} 445 446public: 447 const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; } 448 449 SwitchCase *getNextSwitchCase() { return NextSwitchCase; } 450 451 void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; } 452 453 Stmt *getSubStmt() { return v_getSubStmt(); } 454 455 virtual SourceRange getSourceRange() const { return SourceRange(); } 456 457 static bool classof(const Stmt *T) { 458 return T->getStmtClass() == CaseStmtClass || 459 T->getStmtClass() == DefaultStmtClass; 460 } 461 static bool classof(const SwitchCase *) { return true; } 462protected: 463 virtual Stmt* v_getSubStmt() = 0; 464}; 465 466class CaseStmt : public SwitchCase { 467 enum { SUBSTMT, LHS, RHS, END_EXPR }; 468 Stmt* SubExprs[END_EXPR]; // The expression for the RHS is Non-null for 469 // GNU "case 1 ... 4" extension 470 SourceLocation CaseLoc; 471 SourceLocation EllipsisLoc; 472 SourceLocation ColonLoc; 473 474 virtual Stmt* v_getSubStmt() { return getSubStmt(); } 475public: 476 CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc, 477 SourceLocation ellipsisLoc, SourceLocation colonLoc) 478 : SwitchCase(CaseStmtClass) { 479 SubExprs[SUBSTMT] = 0; 480 SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs); 481 SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs); 482 CaseLoc = caseLoc; 483 EllipsisLoc = ellipsisLoc; 484 ColonLoc = colonLoc; 485 } 486 487 /// \brief Build an empty switch case statement. 488 explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass) { } 489 490 SourceLocation getCaseLoc() const { return CaseLoc; } 491 void setCaseLoc(SourceLocation L) { CaseLoc = L; } 492 SourceLocation getEllipsisLoc() const { return EllipsisLoc; } 493 void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; } 494 SourceLocation getColonLoc() const { return ColonLoc; } 495 void setColonLoc(SourceLocation L) { ColonLoc = L; } 496 497 Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); } 498 Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); } 499 Stmt *getSubStmt() { return SubExprs[SUBSTMT]; } 500 501 const Expr *getLHS() const { 502 return reinterpret_cast<const Expr*>(SubExprs[LHS]); 503 } 504 const Expr *getRHS() const { 505 return reinterpret_cast<const Expr*>(SubExprs[RHS]); 506 } 507 const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; } 508 509 void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; } 510 void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); } 511 void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); } 512 513 514 virtual SourceRange getSourceRange() const { 515 // Handle deeply nested case statements with iteration instead of recursion. 516 const CaseStmt *CS = this; 517 while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt())) 518 CS = CS2; 519 520 return SourceRange(CaseLoc, CS->getSubStmt()->getLocEnd()); 521 } 522 static bool classof(const Stmt *T) { 523 return T->getStmtClass() == CaseStmtClass; 524 } 525 static bool classof(const CaseStmt *) { return true; } 526 527 // Iterators 528 virtual child_iterator child_begin(); 529 virtual child_iterator child_end(); 530}; 531 532class DefaultStmt : public SwitchCase { 533 Stmt* SubStmt; 534 SourceLocation DefaultLoc; 535 SourceLocation ColonLoc; 536 virtual Stmt* v_getSubStmt() { return getSubStmt(); } 537public: 538 DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) : 539 SwitchCase(DefaultStmtClass), SubStmt(substmt), DefaultLoc(DL), 540 ColonLoc(CL) {} 541 542 /// \brief Build an empty default statement. 543 explicit DefaultStmt(EmptyShell) : SwitchCase(DefaultStmtClass) { } 544 545 Stmt *getSubStmt() { return SubStmt; } 546 const Stmt *getSubStmt() const { return SubStmt; } 547 void setSubStmt(Stmt *S) { SubStmt = S; } 548 549 SourceLocation getDefaultLoc() const { return DefaultLoc; } 550 void setDefaultLoc(SourceLocation L) { DefaultLoc = L; } 551 SourceLocation getColonLoc() const { return ColonLoc; } 552 void setColonLoc(SourceLocation L) { ColonLoc = L; } 553 554 virtual SourceRange getSourceRange() const { 555 return SourceRange(DefaultLoc, SubStmt->getLocEnd()); 556 } 557 static bool classof(const Stmt *T) { 558 return T->getStmtClass() == DefaultStmtClass; 559 } 560 static bool classof(const DefaultStmt *) { return true; } 561 562 // Iterators 563 virtual child_iterator child_begin(); 564 virtual child_iterator child_end(); 565}; 566 567class LabelStmt : public Stmt { 568 IdentifierInfo *Label; 569 Stmt *SubStmt; 570 SourceLocation IdentLoc; 571public: 572 LabelStmt(SourceLocation IL, IdentifierInfo *label, Stmt *substmt) 573 : Stmt(LabelStmtClass), Label(label), 574 SubStmt(substmt), IdentLoc(IL) {} 575 576 // \brief Build an empty label statement. 577 explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { } 578 579 SourceLocation getIdentLoc() const { return IdentLoc; } 580 IdentifierInfo *getID() const { return Label; } 581 void setID(IdentifierInfo *II) { Label = II; } 582 const char *getName() const; 583 Stmt *getSubStmt() { return SubStmt; } 584 const Stmt *getSubStmt() const { return SubStmt; } 585 void setIdentLoc(SourceLocation L) { IdentLoc = L; } 586 void setSubStmt(Stmt *SS) { SubStmt = SS; } 587 588 virtual SourceRange getSourceRange() const { 589 return SourceRange(IdentLoc, SubStmt->getLocEnd()); 590 } 591 static bool classof(const Stmt *T) { 592 return T->getStmtClass() == LabelStmtClass; 593 } 594 static bool classof(const LabelStmt *) { return true; } 595 596 // Iterators 597 virtual child_iterator child_begin(); 598 virtual child_iterator child_end(); 599}; 600 601 602/// IfStmt - This represents an if/then/else. 603/// 604class IfStmt : public Stmt { 605 enum { COND, THEN, ELSE, END_EXPR }; 606 Stmt* SubExprs[END_EXPR]; 607 SourceLocation IfLoc; 608 SourceLocation ElseLoc; 609public: 610 IfStmt(SourceLocation IL, Expr *cond, Stmt *then, 611 SourceLocation EL = SourceLocation(), Stmt *elsev = 0) 612 : Stmt(IfStmtClass) { 613 SubExprs[COND] = reinterpret_cast<Stmt*>(cond); 614 SubExprs[THEN] = then; 615 SubExprs[ELSE] = elsev; 616 IfLoc = IL; 617 ElseLoc = EL; 618 } 619 620 /// \brief Build an empty if/then/else statement 621 explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { } 622 623 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 624 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); } 625 const Stmt *getThen() const { return SubExprs[THEN]; } 626 void setThen(Stmt *S) { SubExprs[THEN] = S; } 627 const Stmt *getElse() const { return SubExprs[ELSE]; } 628 void setElse(Stmt *S) { SubExprs[ELSE] = S; } 629 630 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 631 Stmt *getThen() { return SubExprs[THEN]; } 632 Stmt *getElse() { return SubExprs[ELSE]; } 633 634 SourceLocation getIfLoc() const { return IfLoc; } 635 void setIfLoc(SourceLocation L) { IfLoc = L; } 636 SourceLocation getElseLoc() const { return ElseLoc; } 637 void setElseLoc(SourceLocation L) { ElseLoc = L; } 638 639 virtual SourceRange getSourceRange() const { 640 if (SubExprs[ELSE]) 641 return SourceRange(IfLoc, SubExprs[ELSE]->getLocEnd()); 642 else 643 return SourceRange(IfLoc, SubExprs[THEN]->getLocEnd()); 644 } 645 646 static bool classof(const Stmt *T) { 647 return T->getStmtClass() == IfStmtClass; 648 } 649 static bool classof(const IfStmt *) { return true; } 650 651 // Iterators 652 virtual child_iterator child_begin(); 653 virtual child_iterator child_end(); 654}; 655 656/// SwitchStmt - This represents a 'switch' stmt. 657/// 658class SwitchStmt : public Stmt { 659 enum { COND, BODY, END_EXPR }; 660 Stmt* SubExprs[END_EXPR]; 661 // This points to a linked list of case and default statements. 662 SwitchCase *FirstCase; 663 SourceLocation SwitchLoc; 664 665protected: 666 virtual void DoDestroy(ASTContext &Ctx); 667 668public: 669 SwitchStmt(Expr *cond) : Stmt(SwitchStmtClass), FirstCase(0) { 670 SubExprs[COND] = reinterpret_cast<Stmt*>(cond); 671 SubExprs[BODY] = NULL; 672 } 673 674 /// \brief Build a empty switch statement. 675 explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { } 676 677 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 678 const Stmt *getBody() const { return SubExprs[BODY]; } 679 const SwitchCase *getSwitchCaseList() const { return FirstCase; } 680 681 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);} 682 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); } 683 Stmt *getBody() { return SubExprs[BODY]; } 684 void setBody(Stmt *S) { SubExprs[BODY] = S; } 685 SwitchCase *getSwitchCaseList() { return FirstCase; } 686 687 /// \brief Set the case list for this switch statement. 688 /// 689 /// The caller is responsible for incrementing the retain counts on 690 /// all of the SwitchCase statements in this list. 691 void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; } 692 693 SourceLocation getSwitchLoc() const { return SwitchLoc; } 694 void setSwitchLoc(SourceLocation L) { SwitchLoc = L; } 695 696 void setBody(Stmt *S, SourceLocation SL) { 697 SubExprs[BODY] = S; 698 SwitchLoc = SL; 699 } 700 void addSwitchCase(SwitchCase *SC) { 701 assert(!SC->getNextSwitchCase() && "case/default already added to a switch"); 702 SC->Retain(); 703 SC->setNextSwitchCase(FirstCase); 704 FirstCase = SC; 705 } 706 virtual SourceRange getSourceRange() const { 707 return SourceRange(SwitchLoc, SubExprs[BODY]->getLocEnd()); 708 } 709 static bool classof(const Stmt *T) { 710 return T->getStmtClass() == SwitchStmtClass; 711 } 712 static bool classof(const SwitchStmt *) { return true; } 713 714 // Iterators 715 virtual child_iterator child_begin(); 716 virtual child_iterator child_end(); 717}; 718 719 720/// WhileStmt - This represents a 'while' stmt. 721/// 722class WhileStmt : public Stmt { 723 enum { COND, BODY, END_EXPR }; 724 Stmt* SubExprs[END_EXPR]; 725 SourceLocation WhileLoc; 726public: 727 WhileStmt(Expr *cond, Stmt *body, SourceLocation WL) : Stmt(WhileStmtClass) { 728 SubExprs[COND] = reinterpret_cast<Stmt*>(cond); 729 SubExprs[BODY] = body; 730 WhileLoc = WL; 731 } 732 733 /// \brief Build an empty while statement. 734 explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { } 735 736 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 737 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 738 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 739 Stmt *getBody() { return SubExprs[BODY]; } 740 const Stmt *getBody() const { return SubExprs[BODY]; } 741 void setBody(Stmt *S) { SubExprs[BODY] = S; } 742 743 SourceLocation getWhileLoc() const { return WhileLoc; } 744 void setWhileLoc(SourceLocation L) { WhileLoc = L; } 745 746 virtual SourceRange getSourceRange() const { 747 return SourceRange(WhileLoc, SubExprs[BODY]->getLocEnd()); 748 } 749 static bool classof(const Stmt *T) { 750 return T->getStmtClass() == WhileStmtClass; 751 } 752 static bool classof(const WhileStmt *) { return true; } 753 754 // Iterators 755 virtual child_iterator child_begin(); 756 virtual child_iterator child_end(); 757}; 758 759/// DoStmt - This represents a 'do/while' stmt. 760/// 761class DoStmt : public Stmt { 762 enum { COND, BODY, END_EXPR }; 763 Stmt* SubExprs[END_EXPR]; 764 SourceLocation DoLoc; 765 SourceLocation WhileLoc; 766 SourceLocation RParenLoc; // Location of final ')' in do stmt condition. 767 768public: 769 DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL, 770 SourceLocation RP) 771 : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) { 772 SubExprs[COND] = reinterpret_cast<Stmt*>(cond); 773 SubExprs[BODY] = body; 774 } 775 776 /// \brief Build an empty do-while statement. 777 explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { } 778 779 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 780 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 781 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 782 Stmt *getBody() { return SubExprs[BODY]; } 783 const Stmt *getBody() const { return SubExprs[BODY]; } 784 void setBody(Stmt *S) { SubExprs[BODY] = S; } 785 786 SourceLocation getDoLoc() const { return DoLoc; } 787 void setDoLoc(SourceLocation L) { DoLoc = L; } 788 SourceLocation getWhileLoc() const { return WhileLoc; } 789 void setWhileLoc(SourceLocation L) { WhileLoc = L; } 790 791 SourceLocation getRParenLoc() const { return RParenLoc; } 792 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 793 794 virtual SourceRange getSourceRange() const { 795 return SourceRange(DoLoc, RParenLoc); 796 } 797 static bool classof(const Stmt *T) { 798 return T->getStmtClass() == DoStmtClass; 799 } 800 static bool classof(const DoStmt *) { return true; } 801 802 // Iterators 803 virtual child_iterator child_begin(); 804 virtual child_iterator child_end(); 805}; 806 807 808/// ForStmt - This represents a 'for (init;cond;inc)' stmt. Note that any of 809/// the init/cond/inc parts of the ForStmt will be null if they were not 810/// specified in the source. 811/// 812class ForStmt : public Stmt { 813 enum { INIT, COND, INC, BODY, END_EXPR }; 814 Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt. 815 SourceLocation ForLoc; 816 SourceLocation LParenLoc, RParenLoc; 817 818public: 819 ForStmt(Stmt *Init, Expr *Cond, Expr *Inc, Stmt *Body, SourceLocation FL, 820 SourceLocation LP, SourceLocation RP) 821 : Stmt(ForStmtClass) { 822 SubExprs[INIT] = Init; 823 SubExprs[COND] = reinterpret_cast<Stmt*>(Cond); 824 SubExprs[INC] = reinterpret_cast<Stmt*>(Inc); 825 SubExprs[BODY] = Body; 826 ForLoc = FL; 827 LParenLoc = LP; 828 RParenLoc = RP; 829 } 830 831 /// \brief Build an empty for statement. 832 explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { } 833 834 Stmt *getInit() { return SubExprs[INIT]; } 835 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); } 836 Expr *getInc() { return reinterpret_cast<Expr*>(SubExprs[INC]); } 837 Stmt *getBody() { return SubExprs[BODY]; } 838 839 const Stmt *getInit() const { return SubExprs[INIT]; } 840 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);} 841 const Expr *getInc() const { return reinterpret_cast<Expr*>(SubExprs[INC]); } 842 const Stmt *getBody() const { return SubExprs[BODY]; } 843 844 void setInit(Stmt *S) { SubExprs[INIT] = S; } 845 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); } 846 void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); } 847 void setBody(Stmt *S) { SubExprs[BODY] = S; } 848 849 SourceLocation getForLoc() const { return ForLoc; } 850 void setForLoc(SourceLocation L) { ForLoc = L; } 851 SourceLocation getLParenLoc() const { return LParenLoc; } 852 void setLParenLoc(SourceLocation L) { LParenLoc = L; } 853 SourceLocation getRParenLoc() const { return RParenLoc; } 854 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 855 856 virtual SourceRange getSourceRange() const { 857 return SourceRange(ForLoc, SubExprs[BODY]->getLocEnd()); 858 } 859 static bool classof(const Stmt *T) { 860 return T->getStmtClass() == ForStmtClass; 861 } 862 static bool classof(const ForStmt *) { return true; } 863 864 // Iterators 865 virtual child_iterator child_begin(); 866 virtual child_iterator child_end(); 867}; 868 869/// GotoStmt - This represents a direct goto. 870/// 871class GotoStmt : public Stmt { 872 LabelStmt *Label; 873 SourceLocation GotoLoc; 874 SourceLocation LabelLoc; 875public: 876 GotoStmt(LabelStmt *label, SourceLocation GL, SourceLocation LL) 877 : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {} 878 879 /// \brief Build an empty goto statement. 880 explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { } 881 882 LabelStmt *getLabel() const { return Label; } 883 void setLabel(LabelStmt *S) { Label = S; } 884 885 SourceLocation getGotoLoc() const { return GotoLoc; } 886 void setGotoLoc(SourceLocation L) { GotoLoc = L; } 887 SourceLocation getLabelLoc() const { return LabelLoc; } 888 void setLabelLoc(SourceLocation L) { LabelLoc = L; } 889 890 virtual SourceRange getSourceRange() const { 891 return SourceRange(GotoLoc, LabelLoc); 892 } 893 static bool classof(const Stmt *T) { 894 return T->getStmtClass() == GotoStmtClass; 895 } 896 static bool classof(const GotoStmt *) { return true; } 897 898 // Iterators 899 virtual child_iterator child_begin(); 900 virtual child_iterator child_end(); 901}; 902 903/// IndirectGotoStmt - This represents an indirect goto. 904/// 905class IndirectGotoStmt : public Stmt { 906 SourceLocation GotoLoc; 907 SourceLocation StarLoc; 908 Stmt *Target; 909public: 910 IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc, 911 Expr *target) 912 : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc), 913 Target((Stmt*)target) {} 914 915 /// \brief Build an empty indirect goto statement. 916 explicit IndirectGotoStmt(EmptyShell Empty) 917 : Stmt(IndirectGotoStmtClass, Empty) { } 918 919 void setGotoLoc(SourceLocation L) { GotoLoc = L; } 920 SourceLocation getGotoLoc() const { return GotoLoc; } 921 void setStarLoc(SourceLocation L) { StarLoc = L; } 922 SourceLocation getStarLoc() const { return StarLoc; } 923 924 Expr *getTarget(); 925 const Expr *getTarget() const; 926 void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); } 927 928 virtual SourceRange getSourceRange() const { 929 return SourceRange(GotoLoc, Target->getLocEnd()); 930 } 931 932 static bool classof(const Stmt *T) { 933 return T->getStmtClass() == IndirectGotoStmtClass; 934 } 935 static bool classof(const IndirectGotoStmt *) { return true; } 936 937 // Iterators 938 virtual child_iterator child_begin(); 939 virtual child_iterator child_end(); 940}; 941 942 943/// ContinueStmt - This represents a continue. 944/// 945class ContinueStmt : public Stmt { 946 SourceLocation ContinueLoc; 947public: 948 ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {} 949 950 /// \brief Build an empty continue statement. 951 explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { } 952 953 SourceLocation getContinueLoc() const { return ContinueLoc; } 954 void setContinueLoc(SourceLocation L) { ContinueLoc = L; } 955 956 virtual SourceRange getSourceRange() const { 957 return SourceRange(ContinueLoc); 958 } 959 960 static bool classof(const Stmt *T) { 961 return T->getStmtClass() == ContinueStmtClass; 962 } 963 static bool classof(const ContinueStmt *) { return true; } 964 965 // Iterators 966 virtual child_iterator child_begin(); 967 virtual child_iterator child_end(); 968}; 969 970/// BreakStmt - This represents a break. 971/// 972class BreakStmt : public Stmt { 973 SourceLocation BreakLoc; 974public: 975 BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {} 976 977 /// \brief Build an empty break statement. 978 explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { } 979 980 SourceLocation getBreakLoc() const { return BreakLoc; } 981 void setBreakLoc(SourceLocation L) { BreakLoc = L; } 982 983 virtual SourceRange getSourceRange() const { return SourceRange(BreakLoc); } 984 985 static bool classof(const Stmt *T) { 986 return T->getStmtClass() == BreakStmtClass; 987 } 988 static bool classof(const BreakStmt *) { return true; } 989 990 // Iterators 991 virtual child_iterator child_begin(); 992 virtual child_iterator child_end(); 993}; 994 995 996/// ReturnStmt - This represents a return, optionally of an expression: 997/// return; 998/// return 4; 999/// 1000/// Note that GCC allows return with no argument in a function declared to 1001/// return a value, and it allows returning a value in functions declared to 1002/// return void. We explicitly model this in the AST, which means you can't 1003/// depend on the return type of the function and the presence of an argument. 1004/// 1005class ReturnStmt : public Stmt { 1006 Stmt *RetExpr; 1007 SourceLocation RetLoc; 1008public: 1009 ReturnStmt(SourceLocation RL, Expr *E = 0) : Stmt(ReturnStmtClass), 1010 RetExpr((Stmt*) E), RetLoc(RL) {} 1011 1012 /// \brief Build an empty return expression. 1013 explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { } 1014 1015 const Expr *getRetValue() const; 1016 Expr *getRetValue(); 1017 void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); } 1018 1019 SourceLocation getReturnLoc() const { return RetLoc; } 1020 void setReturnLoc(SourceLocation L) { RetLoc = L; } 1021 1022 virtual SourceRange getSourceRange() const; 1023 1024 static bool classof(const Stmt *T) { 1025 return T->getStmtClass() == ReturnStmtClass; 1026 } 1027 static bool classof(const ReturnStmt *) { return true; } 1028 1029 // Iterators 1030 virtual child_iterator child_begin(); 1031 virtual child_iterator child_end(); 1032}; 1033 1034/// AsmStmt - This represents a GNU inline-assembly statement extension. 1035/// 1036class AsmStmt : public Stmt { 1037 SourceLocation AsmLoc, RParenLoc; 1038 StringLiteral *AsmStr; 1039 1040 bool IsSimple; 1041 bool IsVolatile; 1042 1043 unsigned NumOutputs; 1044 unsigned NumInputs; 1045 1046 llvm::SmallVector<std::string, 4> Names; 1047 llvm::SmallVector<StringLiteral*, 4> Constraints; 1048 llvm::SmallVector<Stmt*, 4> Exprs; 1049 1050 llvm::SmallVector<StringLiteral*, 4> Clobbers; 1051public: 1052 AsmStmt(SourceLocation asmloc, bool issimple, bool isvolatile, 1053 unsigned numoutputs, unsigned numinputs, 1054 std::string *names, StringLiteral **constraints, 1055 Expr **exprs, StringLiteral *asmstr, unsigned numclobbers, 1056 StringLiteral **clobbers, SourceLocation rparenloc); 1057 1058 /// \brief Build an empty inline-assembly statement. 1059 explicit AsmStmt(EmptyShell Empty) : Stmt(AsmStmtClass, Empty) { } 1060 1061 SourceLocation getAsmLoc() const { return AsmLoc; } 1062 void setAsmLoc(SourceLocation L) { AsmLoc = L; } 1063 SourceLocation getRParenLoc() const { return RParenLoc; } 1064 void setRParenLoc(SourceLocation L) { RParenLoc = L; } 1065 1066 bool isVolatile() const { return IsVolatile; } 1067 void setVolatile(bool V) { IsVolatile = V; } 1068 bool isSimple() const { return IsSimple; } 1069 void setSimple(bool V) { IsSimple = false; } 1070 1071 //===--- Asm String Analysis ---===// 1072 1073 const StringLiteral *getAsmString() const { return AsmStr; } 1074 StringLiteral *getAsmString() { return AsmStr; } 1075 void setAsmString(StringLiteral *E) { AsmStr = E; } 1076 1077 /// AsmStringPiece - this is part of a decomposed asm string specification 1078 /// (for use with the AnalyzeAsmString function below). An asm string is 1079 /// considered to be a concatenation of these parts. 1080 class AsmStringPiece { 1081 public: 1082 enum Kind { 1083 String, // String in .ll asm string form, "$" -> "$$" and "%%" -> "%". 1084 Operand // Operand reference, with optional modifier %c4. 1085 }; 1086 private: 1087 Kind MyKind; 1088 std::string Str; 1089 unsigned OperandNo; 1090 public: 1091 AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {} 1092 AsmStringPiece(unsigned OpNo, char Modifier) 1093 : MyKind(Operand), Str(), OperandNo(OpNo) { 1094 Str += Modifier; 1095 } 1096 1097 bool isString() const { return MyKind == String; } 1098 bool isOperand() const { return MyKind == Operand; } 1099 1100 const std::string &getString() const { 1101 assert(isString()); 1102 return Str; 1103 } 1104 1105 unsigned getOperandNo() const { 1106 assert(isOperand()); 1107 return OperandNo; 1108 } 1109 1110 /// getModifier - Get the modifier for this operand, if present. This 1111 /// returns '\0' if there was no modifier. 1112 char getModifier() const { 1113 assert(isOperand()); 1114 return Str[0]; 1115 } 1116 }; 1117 1118 /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing 1119 /// it into pieces. If the asm string is erroneous, emit errors and return 1120 /// true, otherwise return false. This handles canonicalization and 1121 /// translation of strings from GCC syntax to LLVM IR syntax, and handles 1122 //// flattening of named references like %[foo] to Operand AsmStringPiece's. 1123 unsigned AnalyzeAsmString(llvm::SmallVectorImpl<AsmStringPiece> &Pieces, 1124 ASTContext &C, unsigned &DiagOffs) const; 1125 1126 1127 //===--- Output operands ---===// 1128 1129 unsigned getNumOutputs() const { return NumOutputs; } 1130 1131 const std::string &getOutputName(unsigned i) const { 1132 return Names[i]; 1133 } 1134 1135 /// getOutputConstraint - Return the constraint string for the specified 1136 /// output operand. All output constraints are known to be non-empty (either 1137 /// '=' or '+'). 1138 std::string getOutputConstraint(unsigned i) const; 1139 1140 const StringLiteral *getOutputConstraintLiteral(unsigned i) const { 1141 return Constraints[i]; 1142 } 1143 StringLiteral *getOutputConstraintLiteral(unsigned i) { 1144 return Constraints[i]; 1145 } 1146 1147 1148 Expr *getOutputExpr(unsigned i); 1149 1150 const Expr *getOutputExpr(unsigned i) const { 1151 return const_cast<AsmStmt*>(this)->getOutputExpr(i); 1152 } 1153 1154 /// isOutputPlusConstraint - Return true if the specified output constraint 1155 /// is a "+" constraint (which is both an input and an output) or false if it 1156 /// is an "=" constraint (just an output). 1157 bool isOutputPlusConstraint(unsigned i) const { 1158 return getOutputConstraint(i)[0] == '+'; 1159 } 1160 1161 /// getNumPlusOperands - Return the number of output operands that have a "+" 1162 /// constraint. 1163 unsigned getNumPlusOperands() const; 1164 1165 //===--- Input operands ---===// 1166 1167 unsigned getNumInputs() const { return NumInputs; } 1168 1169 const std::string &getInputName(unsigned i) const { 1170 return Names[i + NumOutputs]; 1171 } 1172 1173 /// getInputConstraint - Return the specified input constraint. Unlike output 1174 /// constraints, these can be empty. 1175 std::string getInputConstraint(unsigned i) const; 1176 1177 const StringLiteral *getInputConstraintLiteral(unsigned i) const { 1178 return Constraints[i + NumOutputs]; 1179 } 1180 StringLiteral *getInputConstraintLiteral(unsigned i) { 1181 return Constraints[i + NumOutputs]; 1182 } 1183 1184 1185 Expr *getInputExpr(unsigned i); 1186 1187 const Expr *getInputExpr(unsigned i) const { 1188 return const_cast<AsmStmt*>(this)->getInputExpr(i); 1189 } 1190 1191 void setOutputsAndInputs(unsigned NumOutputs, 1192 unsigned NumInputs, 1193 const std::string *Names, 1194 StringLiteral **Constraints, 1195 Stmt **Exprs); 1196 1197 //===--- Other ---===// 1198 1199 /// getNamedOperand - Given a symbolic operand reference like %[foo], 1200 /// translate this into a numeric value needed to reference the same operand. 1201 /// This returns -1 if the operand name is invalid. 1202 int getNamedOperand(const std::string &SymbolicName) const; 1203 1204 1205 1206 unsigned getNumClobbers() const { return Clobbers.size(); } 1207 StringLiteral *getClobber(unsigned i) { return Clobbers[i]; } 1208 const StringLiteral *getClobber(unsigned i) const { return Clobbers[i]; } 1209 void setClobbers(StringLiteral **Clobbers, unsigned NumClobbers); 1210 1211 virtual SourceRange getSourceRange() const { 1212 return SourceRange(AsmLoc, RParenLoc); 1213 } 1214 1215 static bool classof(const Stmt *T) {return T->getStmtClass() == AsmStmtClass;} 1216 static bool classof(const AsmStmt *) { return true; } 1217 1218 // Input expr iterators. 1219 1220 typedef ExprIterator inputs_iterator; 1221 typedef ConstExprIterator const_inputs_iterator; 1222 1223 inputs_iterator begin_inputs() { 1224 return Exprs.data() + NumOutputs; 1225 } 1226 1227 inputs_iterator end_inputs() { 1228 return Exprs.data() + NumOutputs + NumInputs; 1229 } 1230 1231 const_inputs_iterator begin_inputs() const { 1232 return Exprs.data() + NumOutputs; 1233 } 1234 1235 const_inputs_iterator end_inputs() const { 1236 return Exprs.data() + NumOutputs + NumInputs; 1237 } 1238 1239 // Output expr iterators. 1240 1241 typedef ExprIterator outputs_iterator; 1242 typedef ConstExprIterator const_outputs_iterator; 1243 1244 outputs_iterator begin_outputs() { 1245 return Exprs.data(); 1246 } 1247 outputs_iterator end_outputs() { 1248 return Exprs.data() + NumOutputs; 1249 } 1250 1251 const_outputs_iterator begin_outputs() const { 1252 return Exprs.data(); 1253 } 1254 const_outputs_iterator end_outputs() const { 1255 return Exprs.data() + NumOutputs; 1256 } 1257 1258 // Input name iterator. 1259 1260 const std::string *begin_output_names() const { 1261 return &Names[0]; 1262 } 1263 1264 const std::string *end_output_names() const { 1265 return &Names[0] + NumOutputs; 1266 } 1267 1268 // Child iterators 1269 1270 virtual child_iterator child_begin(); 1271 virtual child_iterator child_end(); 1272}; 1273 1274} // end namespace clang 1275 1276#endif 1277