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 | 146 |
1 files changed, 115 insertions, 31 deletions
diff --git a/contrib/llvm/tools/clang/include/clang/AST/Stmt.h b/contrib/llvm/tools/clang/include/clang/AST/Stmt.h index ace53d8..fb94097 100644 --- a/contrib/llvm/tools/clang/include/clang/AST/Stmt.h +++ b/contrib/llvm/tools/clang/include/clang/AST/Stmt.h @@ -62,7 +62,7 @@ namespace clang { Stmt** I; public: ExprIterator(Stmt** i) : I(i) {} - ExprIterator() : I(0) {} + ExprIterator() : I(nullptr) {} ExprIterator& operator++() { ++I; return *this; } ExprIterator operator-(size_t i) { return I-i; } ExprIterator operator+(size_t i) { return I+i; } @@ -81,7 +81,7 @@ namespace clang { const Stmt * const *I; public: ConstExprIterator(const Stmt * const *i) : I(i) {} - ConstExprIterator() : I(0) {} + ConstExprIterator() : I(nullptr) {} ConstExprIterator& operator++() { ++I; return *this; } ConstExprIterator operator+(size_t i) const { return I+i; } ConstExprIterator operator-(size_t i) const { return I-i; } @@ -371,12 +371,12 @@ public: /// \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() const; + void dump(SourceManager &SM) const; void dump(raw_ostream &OS, SourceManager &SM) const; /// dumpColor - same as dump(), but forces color highlighting. - LLVM_ATTRIBUTE_USED void dumpColor() const; + void dumpColor() const; /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST /// back to its original source language syntax. @@ -485,7 +485,13 @@ public: typedef DeclGroupRef::iterator decl_iterator; typedef DeclGroupRef::const_iterator const_decl_iterator; + typedef llvm::iterator_range<decl_iterator> decl_range; + typedef llvm::iterator_range<const_decl_iterator> decl_const_range; + decl_range decls() { return decl_range(decl_begin(), decl_end()); } + decl_const_range decls() const { + return decl_const_range(decl_begin(), decl_end()); + } decl_iterator decl_begin() { return DG.begin(); } decl_iterator decl_end() { return DG.end(); } const_decl_iterator decl_begin() const { return DG.begin(); } @@ -549,13 +555,13 @@ public: // \brief Build an empty compound statement with a location. explicit CompoundStmt(SourceLocation Loc) - : Stmt(CompoundStmtClass), Body(0), LBracLoc(Loc), RBracLoc(Loc) { + : Stmt(CompoundStmtClass), Body(nullptr), LBracLoc(Loc), RBracLoc(Loc) { CompoundStmtBits.NumStmts = 0; } // \brief Build an empty compound statement. explicit CompoundStmt(EmptyShell Empty) - : Stmt(CompoundStmtClass, Empty), Body(0) { + : Stmt(CompoundStmtClass, Empty), Body(nullptr) { CompoundStmtBits.NumStmts = 0; } @@ -565,9 +571,12 @@ public: unsigned size() const { return CompoundStmtBits.NumStmts; } typedef Stmt** body_iterator; + typedef llvm::iterator_range<body_iterator> body_range; + + body_range body() { return body_range(body_begin(), body_end()); } body_iterator body_begin() { return Body; } body_iterator body_end() { return Body + size(); } - Stmt *body_back() { return !body_empty() ? Body[size()-1] : 0; } + Stmt *body_back() { return !body_empty() ? Body[size()-1] : nullptr; } void setLastStmt(Stmt *S) { assert(!body_empty() && "setLastStmt"); @@ -575,9 +584,16 @@ public: } typedef Stmt* const * const_body_iterator; + typedef llvm::iterator_range<const_body_iterator> body_const_range; + + body_const_range body() const { + return body_const_range(body_begin(), body_end()); + } const_body_iterator body_begin() const { return Body; } const_body_iterator body_end() const { return Body + size(); } - const Stmt *body_back() const { return !body_empty() ? Body[size()-1] : 0; } + const Stmt *body_back() const { + return !body_empty() ? Body[size() - 1] : nullptr; + } typedef std::reverse_iterator<body_iterator> reverse_body_iterator; reverse_body_iterator body_rbegin() { @@ -612,11 +628,11 @@ public: // Iterators child_range children() { - return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts); + return child_range(Body, Body + CompoundStmtBits.NumStmts); } const_child_range children() const { - return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts); + return child_range(Body, Body + CompoundStmtBits.NumStmts); } }; @@ -630,10 +646,11 @@ protected: SourceLocation ColonLoc; SwitchCase(StmtClass SC, SourceLocation KWLoc, SourceLocation ColonLoc) - : Stmt(SC), NextSwitchCase(0), KeywordLoc(KWLoc), ColonLoc(ColonLoc) {} + : Stmt(SC), NextSwitchCase(nullptr), KeywordLoc(KWLoc), ColonLoc(ColonLoc) { + } SwitchCase(StmtClass SC, EmptyShell) - : Stmt(SC), NextSwitchCase(0) {} + : Stmt(SC), NextSwitchCase(nullptr) {} public: const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; } @@ -670,7 +687,7 @@ public: CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc) : SwitchCase(CaseStmtClass, caseLoc, colonLoc) { - SubExprs[SUBSTMT] = 0; + SubExprs[SUBSTMT] = nullptr; SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs); SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs); EllipsisLoc = ellipsisLoc; @@ -802,20 +819,24 @@ class AttributedStmt : public Stmt { Stmt *SubStmt; SourceLocation AttrLoc; unsigned NumAttrs; - const Attr *Attrs[1]; friend class ASTStmtReader; AttributedStmt(SourceLocation Loc, ArrayRef<const Attr*> Attrs, Stmt *SubStmt) : Stmt(AttributedStmtClass), SubStmt(SubStmt), AttrLoc(Loc), NumAttrs(Attrs.size()) { - memcpy(this->Attrs, Attrs.data(), Attrs.size() * sizeof(Attr*)); + memcpy(getAttrArrayPtr(), Attrs.data(), Attrs.size() * sizeof(Attr *)); } explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs) : Stmt(AttributedStmtClass, Empty), NumAttrs(NumAttrs) { - memset(Attrs, 0, NumAttrs * sizeof(Attr*)); + memset(getAttrArrayPtr(), 0, NumAttrs * sizeof(Attr *)); + } + + Attr *const *getAttrArrayPtr() const { + return reinterpret_cast<Attr *const *>(this + 1); } + Attr **getAttrArrayPtr() { return reinterpret_cast<Attr **>(this + 1); } public: static AttributedStmt *Create(const ASTContext &C, SourceLocation Loc, @@ -825,7 +846,7 @@ public: SourceLocation getAttrLoc() const { return AttrLoc; } ArrayRef<const Attr*> getAttrs() const { - return ArrayRef<const Attr*>(Attrs, NumAttrs); + return ArrayRef<const Attr*>(getAttrArrayPtr(), NumAttrs); } Stmt *getSubStmt() { return SubStmt; } const Stmt *getSubStmt() const { return SubStmt; } @@ -852,7 +873,8 @@ class IfStmt : public Stmt { public: IfStmt(const ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond, - Stmt *then, SourceLocation EL = SourceLocation(), Stmt *elsev = 0); + Stmt *then, SourceLocation EL = SourceLocation(), + Stmt *elsev = nullptr); /// \brief Build an empty if/then/else statement explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { } @@ -1320,7 +1342,8 @@ class ReturnStmt : public Stmt { public: ReturnStmt(SourceLocation RL) - : Stmt(ReturnStmtClass), RetExpr(0), RetLoc(RL), NRVOCandidate(0) { } + : Stmt(ReturnStmtClass), RetExpr(nullptr), RetLoc(RL), + NRVOCandidate(nullptr) {} ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate) : Stmt(ReturnStmtClass), RetExpr((Stmt*) E), RetLoc(RL), @@ -1389,7 +1412,7 @@ protected: public: /// \brief Build an empty inline-assembly statement. explicit AsmStmt(StmtClass SC, EmptyShell Empty) : - Stmt(SC, Empty), Exprs(0) { } + Stmt(SC, Empty), Exprs(nullptr) { } SourceLocation getAsmLoc() const { return AsmLoc; } void setAsmLoc(SourceLocation L) { AsmLoc = L; } @@ -1454,6 +1477,8 @@ public: typedef ExprIterator inputs_iterator; typedef ConstExprIterator const_inputs_iterator; + typedef llvm::iterator_range<inputs_iterator> inputs_range; + typedef llvm::iterator_range<const_inputs_iterator> inputs_const_range; inputs_iterator begin_inputs() { return &Exprs[0] + NumOutputs; @@ -1463,6 +1488,8 @@ public: return &Exprs[0] + NumOutputs + NumInputs; } + inputs_range inputs() { return inputs_range(begin_inputs(), end_inputs()); } + const_inputs_iterator begin_inputs() const { return &Exprs[0] + NumOutputs; } @@ -1471,10 +1498,16 @@ public: return &Exprs[0] + NumOutputs + NumInputs; } + inputs_const_range inputs() const { + return inputs_const_range(begin_inputs(), end_inputs()); + } + // Output expr iterators. typedef ExprIterator outputs_iterator; typedef ConstExprIterator const_outputs_iterator; + typedef llvm::iterator_range<outputs_iterator> outputs_range; + typedef llvm::iterator_range<const_outputs_iterator> outputs_const_range; outputs_iterator begin_outputs() { return &Exprs[0]; @@ -1482,6 +1515,9 @@ public: outputs_iterator end_outputs() { return &Exprs[0] + NumOutputs; } + outputs_range outputs() { + return outputs_range(begin_outputs(), end_outputs()); + } const_outputs_iterator begin_outputs() const { return &Exprs[0]; @@ -1489,6 +1525,9 @@ public: const_outputs_iterator end_outputs() const { return &Exprs[0] + NumOutputs; } + outputs_const_range outputs() const { + return outputs_const_range(begin_outputs(), end_outputs()); + } child_range children() { return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs); @@ -1517,7 +1556,7 @@ public: /// \brief Build an empty inline-assembly statement. explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty), - Constraints(0), Clobbers(0), Names(0) { } + Constraints(nullptr), Clobbers(nullptr), Names(nullptr) { } SourceLocation getRParenLoc() const { return RParenLoc; } void setRParenLoc(SourceLocation L) { RParenLoc = L; } @@ -1693,7 +1732,7 @@ public: /// \brief Build an empty MS-style inline-assembly statement. explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty), - NumAsmToks(0), AsmToks(0), Constraints(0), Clobbers(0) { } + NumAsmToks(0), AsmToks(nullptr), Constraints(nullptr), Clobbers(nullptr) { } SourceLocation getLBraceLoc() const { return LBraceLoc; } void setLBraceLoc(SourceLocation L) { LBraceLoc = L; } @@ -1767,7 +1806,7 @@ public: } child_range children() { - return child_range(&Exprs[0], &Exprs[0]); + return child_range(&Exprs[0], &Exprs[NumInputs + NumOutputs]); } }; @@ -1853,22 +1892,24 @@ class SEHTryStmt : public Stmt { bool IsCXXTry; SourceLocation TryLoc; Stmt *Children[2]; + int HandlerIndex; + int HandlerParentIndex; enum { TRY = 0, HANDLER = 1 }; SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try' - SourceLocation TryLoc, - Stmt *TryBlock, - Stmt *Handler); + SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler, + int HandlerIndex, int HandlerParentIndex); friend class ASTReader; friend class ASTStmtReader; explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) { } public: - static SEHTryStmt* Create(const ASTContext &C, bool isCXXTry, + static SEHTryStmt *Create(const ASTContext &C, bool isCXXTry, SourceLocation TryLoc, Stmt *TryBlock, - Stmt *Handler); + Stmt *Handler, int HandlerIndex, + int HandlerParentIndex); SourceLocation getLocStart() const LLVM_READONLY { return getTryLoc(); } SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); } @@ -1895,6 +1936,34 @@ public: static bool classof(const Stmt *T) { return T->getStmtClass() == SEHTryStmtClass; } + + int getHandlerIndex() const { return HandlerIndex; } + int getHandlerParentIndex() const { return HandlerParentIndex; } +}; + +/// Represents a __leave statement. +/// +class SEHLeaveStmt : public Stmt { + SourceLocation LeaveLoc; +public: + explicit SEHLeaveStmt(SourceLocation LL) + : Stmt(SEHLeaveStmtClass), LeaveLoc(LL) {} + + /// \brief Build an empty __leave statement. + explicit SEHLeaveStmt(EmptyShell Empty) : Stmt(SEHLeaveStmtClass, Empty) { } + + SourceLocation getLeaveLoc() const { return LeaveLoc; } + void setLeaveLoc(SourceLocation L) { LeaveLoc = L; } + + SourceLocation getLocStart() const LLVM_READONLY { return LeaveLoc; } + SourceLocation getLocEnd() const LLVM_READONLY { return LeaveLoc; } + + static bool classof(const Stmt *T) { + return T->getStmtClass() == SEHLeaveStmtClass; + } + + // Iterators + child_range children() { return child_range(); } }; /// \brief This captures a statement into a function. For example, the following @@ -1928,11 +1997,12 @@ public: /// /// \param Var The variable being captured, or null if capturing this. /// - Capture(SourceLocation Loc, VariableCaptureKind Kind, VarDecl *Var = 0) + Capture(SourceLocation Loc, VariableCaptureKind Kind, + VarDecl *Var = nullptr) : VarAndKind(Var, Kind), Loc(Loc) { switch (Kind) { case VCK_This: - assert(Var == 0 && "'this' capture cannot have a variable!"); + assert(!Var && "'this' capture cannot have a variable!"); break; case VCK_ByRef: assert(Var && "capturing by reference must have a variable!"); @@ -2042,6 +2112,15 @@ public: /// \brief An iterator that walks over the captures. typedef Capture *capture_iterator; typedef const Capture *const_capture_iterator; + typedef llvm::iterator_range<capture_iterator> capture_range; + typedef llvm::iterator_range<const_capture_iterator> capture_const_range; + + capture_range captures() { + return capture_range(capture_begin(), capture_end()); + } + capture_const_range captures() const { + return capture_const_range(capture_begin(), capture_end()); + } /// \brief Retrieve an iterator pointing to the first capture. capture_iterator capture_begin() { return getStoredCaptures(); } @@ -2058,6 +2137,11 @@ public: /// \brief Iterator that walks over the capture initialization arguments. typedef Expr **capture_init_iterator; + typedef llvm::iterator_range<capture_init_iterator> capture_init_range; + + capture_init_range capture_inits() const { + return capture_init_range(capture_init_begin(), capture_init_end()); + } /// \brief Retrieve the first initialization argument. capture_init_iterator capture_init_begin() const { |