diff options
Diffstat (limited to 'contrib/llvm/tools/clang/include/clang/AST/Stmt.h')
-rw-r--r-- | contrib/llvm/tools/clang/include/clang/AST/Stmt.h | 229 |
1 files changed, 126 insertions, 103 deletions
diff --git a/contrib/llvm/tools/clang/include/clang/AST/Stmt.h b/contrib/llvm/tools/clang/include/clang/AST/Stmt.h index a9bbb48..cf8fc24 100644 --- a/contrib/llvm/tools/clang/include/clang/AST/Stmt.h +++ b/contrib/llvm/tools/clang/include/clang/AST/Stmt.h @@ -14,16 +14,14 @@ #ifndef LLVM_CLANG_AST_STMT_H #define LLVM_CLANG_AST_STMT_H +#include "clang/AST/DeclGroup.h" +#include "clang/AST/StmtIterator.h" +#include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/SourceLocation.h" -#include "clang/AST/PrettyPrinter.h" -#include "clang/AST/StmtIterator.h" -#include "clang/AST/DeclGroup.h" -#include "clang/AST/Attr.h" -#include "clang/Lex/Token.h" -#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/Support/Compiler.h" -#include "llvm/Support/raw_ostream.h" +#include "llvm/Support/ErrorHandling.h" #include <string> namespace llvm { @@ -32,15 +30,19 @@ namespace llvm { namespace clang { class ASTContext; - class Expr; + class Attr; class Decl; - class ParmVarDecl; - class QualType; + class Expr; class IdentifierInfo; class LabelDecl; + class ParmVarDecl; + class PrinterHelper; + struct PrintingPolicy; + class QualType; class SourceManager; class StringLiteral; class SwitchStmt; + class Token; class VarDecl; //===--------------------------------------------------------------------===// @@ -172,11 +174,20 @@ protected: unsigned Kind : 2; }; + enum APFloatSemantics { + IEEEhalf, + IEEEsingle, + IEEEdouble, + x87DoubleExtended, + IEEEquad, + PPCDoubleDouble + }; + class FloatingLiteralBitfields { friend class FloatingLiteral; unsigned : NumExprBits; - unsigned IsIEEE : 1; // Distinguishes between PPC128 and IEEE128. + unsigned Semantics : 3; // Provides semantics for APFloat construction unsigned IsExact : 1; }; @@ -302,14 +313,10 @@ public: // Only allow allocation of Stmts using the allocator in ASTContext // or by doing a placement new. void* operator new(size_t bytes, ASTContext& C, - unsigned alignment = 8) throw() { - return ::operator new(bytes, C, alignment); - } + unsigned alignment = 8) throw(); void* operator new(size_t bytes, ASTContext* C, - unsigned alignment = 8) throw() { - return ::operator new(bytes, *C, alignment); - } + unsigned alignment = 8) throw(); void* operator new(size_t bytes, void* mem) throw() { return mem; @@ -360,16 +367,14 @@ public: static void EnableStatistics(); static void PrintStats(); - /// dump - This does a local dump of the specified AST fragment. It dumps the - /// specified node and a few nodes underneath it, but not the whole subtree. - /// This is useful in a debugger. + /// \brief Dumps the specified AST fragment and all subtrees to + /// \c llvm::errs(). LLVM_ATTRIBUTE_USED void dump() const; LLVM_ATTRIBUTE_USED void dump(SourceManager &SM) const; void dump(raw_ostream &OS, SourceManager &SM) const; - /// dumpAll - This does a dump of the specified AST fragment and all subtrees. - void dumpAll() const; - void dumpAll(SourceManager &SM) const; + /// dumpColor - same as dump(), but forces color highlighting. + LLVM_ATTRIBUTE_USED void dumpColor() const; /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST /// back to its original source language syntax. @@ -470,9 +475,8 @@ public: SourceLocation getEndLoc() const { return EndLoc; } void setEndLoc(SourceLocation L) { EndLoc = L; } - SourceRange getSourceRange() const LLVM_READONLY { - return SourceRange(StartLoc, EndLoc); - } + SourceLocation getLocStart() const LLVM_READONLY { return StartLoc; } + SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; } static bool classof(const Stmt *T) { return T->getStmtClass() == DeclStmtClass; @@ -526,7 +530,8 @@ public: bool hasLeadingEmptyMacro() const { return HasLeadingEmptyMacro; } - SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(SemiLoc); } + SourceLocation getLocStart() const LLVM_READONLY { return SemiLoc; } + SourceLocation getLocEnd() const LLVM_READONLY { return SemiLoc; } static bool classof(const Stmt *T) { return T->getStmtClass() == NullStmtClass; @@ -544,7 +549,7 @@ class CompoundStmt : public Stmt { Stmt** Body; SourceLocation LBracLoc, RBracLoc; public: - CompoundStmt(ASTContext &C, Stmt **StmtStart, unsigned NumStmts, + CompoundStmt(ASTContext &C, ArrayRef<Stmt*> Stmts, SourceLocation LB, SourceLocation RB); // \brief Build an empty compound statment with a location. @@ -598,9 +603,8 @@ public: return const_reverse_body_iterator(body_begin()); } - SourceRange getSourceRange() const LLVM_READONLY { - return SourceRange(LBracLoc, RBracLoc); - } + SourceLocation getLocStart() const LLVM_READONLY { return LBracLoc; } + SourceLocation getLocEnd() const LLVM_READONLY { return RBracLoc; } SourceLocation getLBracLoc() const { return LBracLoc; } void setLBracLoc(SourceLocation L) { LBracLoc = L; } @@ -627,8 +631,14 @@ protected: // A pointer to the following CaseStmt or DefaultStmt class, // used by SwitchStmt. SwitchCase *NextSwitchCase; + SourceLocation KeywordLoc; + SourceLocation ColonLoc; - SwitchCase(StmtClass SC) : Stmt(SC), NextSwitchCase(0) {} + SwitchCase(StmtClass SC, SourceLocation KWLoc, SourceLocation ColonLoc) + : Stmt(SC), NextSwitchCase(0), KeywordLoc(KWLoc), ColonLoc(ColonLoc) {} + + SwitchCase(StmtClass SC, EmptyShell) + : Stmt(SC), NextSwitchCase(0) {} public: const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; } @@ -637,12 +647,18 @@ public: void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; } + SourceLocation getKeywordLoc() const { return KeywordLoc; } + void setKeywordLoc(SourceLocation L) { KeywordLoc = L; } + SourceLocation getColonLoc() const { return ColonLoc; } + void setColonLoc(SourceLocation L) { ColonLoc = L; } + Stmt *getSubStmt(); const Stmt *getSubStmt() const { return const_cast<SwitchCase*>(this)->getSubStmt(); } - SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(); } + SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; } + SourceLocation getLocEnd() const LLVM_READONLY; static bool classof(const Stmt *T) { return T->getStmtClass() == CaseStmtClass || @@ -654,26 +670,22 @@ class CaseStmt : public SwitchCase { enum { LHS, RHS, SUBSTMT, END_EXPR }; Stmt* SubExprs[END_EXPR]; // The expression for the RHS is Non-null for // GNU "case 1 ... 4" extension - SourceLocation CaseLoc; SourceLocation EllipsisLoc; - SourceLocation ColonLoc; public: CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc) - : SwitchCase(CaseStmtClass) { + : SwitchCase(CaseStmtClass, caseLoc, colonLoc) { SubExprs[SUBSTMT] = 0; SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs); SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs); - CaseLoc = caseLoc; EllipsisLoc = ellipsisLoc; - ColonLoc = colonLoc; } /// \brief Build an empty switch case statement. - explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass) { } + explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass, Empty) { } - SourceLocation getCaseLoc() const { return CaseLoc; } - void setCaseLoc(SourceLocation L) { CaseLoc = L; } + SourceLocation getCaseLoc() const { return KeywordLoc; } + void setCaseLoc(SourceLocation L) { KeywordLoc = L; } SourceLocation getEllipsisLoc() const { return EllipsisLoc; } void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; } SourceLocation getColonLoc() const { return ColonLoc; } @@ -695,15 +707,16 @@ public: void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); } void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); } - - SourceRange getSourceRange() const LLVM_READONLY { + SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; } + SourceLocation getLocEnd() const LLVM_READONLY { // Handle deeply nested case statements with iteration instead of recursion. const CaseStmt *CS = this; while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt())) CS = CS2; - return SourceRange(CaseLoc, CS->getSubStmt()->getLocEnd()); + return CS->getSubStmt()->getLocEnd(); } + static bool classof(const Stmt *T) { return T->getStmtClass() == CaseStmtClass; } @@ -716,28 +729,26 @@ public: class DefaultStmt : public SwitchCase { Stmt* SubStmt; - SourceLocation DefaultLoc; - SourceLocation ColonLoc; public: DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) : - SwitchCase(DefaultStmtClass), SubStmt(substmt), DefaultLoc(DL), - ColonLoc(CL) {} + SwitchCase(DefaultStmtClass, DL, CL), SubStmt(substmt) {} /// \brief Build an empty default statement. - explicit DefaultStmt(EmptyShell) : SwitchCase(DefaultStmtClass) { } + explicit DefaultStmt(EmptyShell Empty) + : SwitchCase(DefaultStmtClass, Empty) { } Stmt *getSubStmt() { return SubStmt; } const Stmt *getSubStmt() const { return SubStmt; } void setSubStmt(Stmt *S) { SubStmt = S; } - SourceLocation getDefaultLoc() const { return DefaultLoc; } - void setDefaultLoc(SourceLocation L) { DefaultLoc = L; } + SourceLocation getDefaultLoc() const { return KeywordLoc; } + void setDefaultLoc(SourceLocation L) { KeywordLoc = L; } SourceLocation getColonLoc() const { return ColonLoc; } void setColonLoc(SourceLocation L) { ColonLoc = L; } - SourceRange getSourceRange() const LLVM_READONLY { - return SourceRange(DefaultLoc, SubStmt->getLocEnd()); - } + SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; } + SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();} + static bool classof(const Stmt *T) { return T->getStmtClass() == DefaultStmtClass; } @@ -746,6 +757,11 @@ public: child_range children() { return child_range(&SubStmt, &SubStmt+1); } }; +inline SourceLocation SwitchCase::getLocEnd() const { + if (const CaseStmt *CS = dyn_cast<CaseStmt>(this)) + return CS->getLocEnd(); + return cast<DefaultStmt>(this)->getLocEnd(); +} /// LabelStmt - Represents a label, which has a substatement. For example: /// foo: return; @@ -771,9 +787,9 @@ public: void setIdentLoc(SourceLocation L) { IdentLoc = L; } void setSubStmt(Stmt *SS) { SubStmt = SS; } - SourceRange getSourceRange() const LLVM_READONLY { - return SourceRange(IdentLoc, SubStmt->getLocEnd()); - } + SourceLocation getLocStart() const LLVM_READONLY { return IdentLoc; } + SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();} + child_range children() { return child_range(&SubStmt, &SubStmt+1); } static bool classof(const Stmt *T) { @@ -819,9 +835,9 @@ public: Stmt *getSubStmt() { return SubStmt; } const Stmt *getSubStmt() const { return SubStmt; } - SourceRange getSourceRange() const LLVM_READONLY { - return SourceRange(AttrLoc, SubStmt->getLocEnd()); - } + SourceLocation getLocStart() const LLVM_READONLY { return AttrLoc; } + SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();} + child_range children() { return child_range(&SubStmt, &SubStmt + 1); } static bool classof(const Stmt *T) { @@ -879,11 +895,12 @@ public: SourceLocation getElseLoc() const { return ElseLoc; } void setElseLoc(SourceLocation L) { ElseLoc = L; } - SourceRange getSourceRange() const LLVM_READONLY { + SourceLocation getLocStart() const LLVM_READONLY { return IfLoc; } + SourceLocation getLocEnd() const LLVM_READONLY { if (SubExprs[ELSE]) - return SourceRange(IfLoc, SubExprs[ELSE]->getLocEnd()); + return SubExprs[ELSE]->getLocEnd(); else - return SourceRange(IfLoc, SubExprs[THEN]->getLocEnd()); + return SubExprs[THEN]->getLocEnd(); } // Iterators over subexpressions. The iterators will include iterating @@ -977,9 +994,11 @@ public: return (bool) AllEnumCasesCovered; } - SourceRange getSourceRange() const LLVM_READONLY { - return SourceRange(SwitchLoc, SubExprs[BODY]->getLocEnd()); + SourceLocation getLocStart() const LLVM_READONLY { return SwitchLoc; } + SourceLocation getLocEnd() const LLVM_READONLY { + return SubExprs[BODY]->getLocEnd(); } + // Iterators child_range children() { return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); @@ -1031,9 +1050,11 @@ public: SourceLocation getWhileLoc() const { return WhileLoc; } void setWhileLoc(SourceLocation L) { WhileLoc = L; } - SourceRange getSourceRange() const LLVM_READONLY { - return SourceRange(WhileLoc, SubExprs[BODY]->getLocEnd()); + SourceLocation getLocStart() const LLVM_READONLY { return WhileLoc; } + SourceLocation getLocEnd() const LLVM_READONLY { + return SubExprs[BODY]->getLocEnd(); } + static bool classof(const Stmt *T) { return T->getStmtClass() == WhileStmtClass; } @@ -1079,9 +1100,9 @@ public: SourceLocation getRParenLoc() const { return RParenLoc; } void setRParenLoc(SourceLocation L) { RParenLoc = L; } - SourceRange getSourceRange() const LLVM_READONLY { - return SourceRange(DoLoc, RParenLoc); - } + SourceLocation getLocStart() const LLVM_READONLY { return DoLoc; } + SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } + static bool classof(const Stmt *T) { return T->getStmtClass() == DoStmtClass; } @@ -1150,9 +1171,11 @@ public: SourceLocation getRParenLoc() const { return RParenLoc; } void setRParenLoc(SourceLocation L) { RParenLoc = L; } - SourceRange getSourceRange() const LLVM_READONLY { - return SourceRange(ForLoc, SubExprs[BODY]->getLocEnd()); + SourceLocation getLocStart() const LLVM_READONLY { return ForLoc; } + SourceLocation getLocEnd() const LLVM_READONLY { + return SubExprs[BODY]->getLocEnd(); } + static bool classof(const Stmt *T) { return T->getStmtClass() == ForStmtClass; } @@ -1184,9 +1207,9 @@ public: SourceLocation getLabelLoc() const { return LabelLoc; } void setLabelLoc(SourceLocation L) { LabelLoc = L; } - SourceRange getSourceRange() const LLVM_READONLY { - return SourceRange(GotoLoc, LabelLoc); - } + SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; } + SourceLocation getLocEnd() const LLVM_READONLY { return LabelLoc; } + static bool classof(const Stmt *T) { return T->getStmtClass() == GotoStmtClass; } @@ -1227,9 +1250,8 @@ public: return const_cast<IndirectGotoStmt*>(this)->getConstantTarget(); } - SourceRange getSourceRange() const LLVM_READONLY { - return SourceRange(GotoLoc, Target->getLocEnd()); - } + SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; } + SourceLocation getLocEnd() const LLVM_READONLY { return Target->getLocEnd(); } static bool classof(const Stmt *T) { return T->getStmtClass() == IndirectGotoStmtClass; @@ -1253,9 +1275,8 @@ public: SourceLocation getContinueLoc() const { return ContinueLoc; } void setContinueLoc(SourceLocation L) { ContinueLoc = L; } - SourceRange getSourceRange() const LLVM_READONLY { - return SourceRange(ContinueLoc); - } + SourceLocation getLocStart() const LLVM_READONLY { return ContinueLoc; } + SourceLocation getLocEnd() const LLVM_READONLY { return ContinueLoc; } static bool classof(const Stmt *T) { return T->getStmtClass() == ContinueStmtClass; @@ -1278,7 +1299,8 @@ public: SourceLocation getBreakLoc() const { return BreakLoc; } void setBreakLoc(SourceLocation L) { BreakLoc = L; } - SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(BreakLoc); } + SourceLocation getLocStart() const LLVM_READONLY { return BreakLoc; } + SourceLocation getLocEnd() const LLVM_READONLY { return BreakLoc; } static bool classof(const Stmt *T) { return T->getStmtClass() == BreakStmtClass; @@ -1329,7 +1351,10 @@ public: const VarDecl *getNRVOCandidate() const { return NRVOCandidate; } void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; } - SourceRange getSourceRange() const LLVM_READONLY; + SourceLocation getLocStart() const LLVM_READONLY { return RetLoc; } + SourceLocation getLocEnd() const LLVM_READONLY { + return RetExpr ? RetExpr->getLocEnd() : RetLoc; + } static bool classof(const Stmt *T) { return T->getStmtClass() == ReturnStmtClass; @@ -1381,7 +1406,8 @@ public: bool isVolatile() const { return IsVolatile; } void setVolatile(bool V) { IsVolatile = V; } - SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(); } + SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); } + SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); } //===--- Asm String Analysis ---===// @@ -1636,9 +1662,8 @@ public: return Clobbers[i]; } - SourceRange getSourceRange() const LLVM_READONLY { - return SourceRange(AsmLoc, RParenLoc); - } + SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; } + SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; } static bool classof(const Stmt *T) { return T->getStmtClass() == GCCAsmStmtClass; @@ -1648,7 +1673,7 @@ public: /// This represents a Microsoft inline-assembly statement extension. /// class MSAsmStmt : public AsmStmt { - SourceLocation AsmLoc, LBraceLoc, EndLoc; + SourceLocation LBraceLoc, EndLoc; std::string AsmStr; unsigned NumAsmToks; @@ -1717,9 +1742,9 @@ public: StringRef getClobber(unsigned i) const { return Clobbers[i]; } - SourceRange getSourceRange() const LLVM_READONLY { - return SourceRange(AsmLoc, EndLoc); - } + SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; } + SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; } + static bool classof(const Stmt *T) { return T->getStmtClass() == MSAsmStmtClass; } @@ -1748,9 +1773,9 @@ public: SourceLocation ExceptLoc, Expr *FilterExpr, Stmt *Block); - SourceRange getSourceRange() const LLVM_READONLY { - return SourceRange(getExceptLoc(), getEndLoc()); - } + + SourceLocation getLocStart() const LLVM_READONLY { return getExceptLoc(); } + SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); } SourceLocation getExceptLoc() const { return Loc; } SourceLocation getEndLoc() const { return getBlock()->getLocEnd(); } @@ -1760,7 +1785,7 @@ public: } CompoundStmt *getBlock() const { - return llvm::cast<CompoundStmt>(Children[BLOCK]); + return cast<CompoundStmt>(Children[BLOCK]); } child_range children() { @@ -1789,14 +1814,13 @@ public: SourceLocation FinallyLoc, Stmt *Block); - SourceRange getSourceRange() const LLVM_READONLY { - return SourceRange(getFinallyLoc(), getEndLoc()); - } + SourceLocation getLocStart() const LLVM_READONLY { return getFinallyLoc(); } + SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); } SourceLocation getFinallyLoc() const { return Loc; } SourceLocation getEndLoc() const { return Block->getLocEnd(); } - CompoundStmt *getBlock() const { return llvm::cast<CompoundStmt>(Block); } + CompoundStmt *getBlock() const { return cast<CompoundStmt>(Block); } child_range children() { return child_range(&Block,&Block+1); @@ -1831,9 +1855,8 @@ public: Stmt *TryBlock, Stmt *Handler); - SourceRange getSourceRange() const LLVM_READONLY { - return SourceRange(getTryLoc(), getEndLoc()); - } + SourceLocation getLocStart() const LLVM_READONLY { return getTryLoc(); } + SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); } SourceLocation getTryLoc() const { return TryLoc; } SourceLocation getEndLoc() const { return Children[HANDLER]->getLocEnd(); } @@ -1841,7 +1864,7 @@ public: bool getIsCXXTry() const { return IsCXXTry; } CompoundStmt* getTryBlock() const { - return llvm::cast<CompoundStmt>(Children[TRY]); + return cast<CompoundStmt>(Children[TRY]); } Stmt *getHandler() const { return Children[HANDLER]; } |