diff options
author | John McCall <rjmccall@apple.com> | 2011-02-09 08:16:59 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2011-02-09 08:16:59 +0000 |
commit | 63c00d7f35fa060c0a446c9df3a4402d9c7757fe (patch) | |
tree | 64f68effbaf44e33590151cab184481c9313db35 | |
parent | f0ed580ea5cdc171973c1ac259a9ee21badb80d8 (diff) |
Remove vtables from the Stmt hierarchy; this was pretty easy as
there were only three virtual methods of any significance.
The primary way to grab child iterators now is with
Stmt::child_range children();
Stmt::const_child_range children() const;
where a child_range is just a std::pair of iterators suitable for
being llvm::tie'd to some locals. I've left the old child_begin()
and child_end() accessors in place, but it's probably a substantial
penalty to grab the iterators individually now, since the
switch-based dispatch is kindof inherently slower than vtable
dispatch. Grabbing them together is probably a slight win over the
status quo, although of course we could've achieved that with vtables, too.
I also reclassified SwitchCase (correctly) as an abstract Stmt
class, which (as the first such class that wasn't an Expr subclass)
required some fiddling in a few places.
There are somewhat gross metaprogramming hooks in place to ensure
that new statements/expressions continue to implement
getSourceRange() and children(). I had to work around a recent clang
bug; dgregor actually fixed it already, but I didn't want to
introduce a selfhosting dependency on ToT.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125183 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/Expr.h | 203 | ||||
-rw-r--r-- | include/clang/AST/ExprCXX.h | 166 | ||||
-rw-r--r-- | include/clang/AST/ExprObjC.h | 49 | ||||
-rw-r--r-- | include/clang/AST/RecursiveASTVisitor.h | 1 | ||||
-rw-r--r-- | include/clang/AST/Stmt.h | 162 | ||||
-rw-r--r-- | include/clang/AST/StmtCXX.h | 12 | ||||
-rw-r--r-- | include/clang/AST/StmtIterator.h | 11 | ||||
-rw-r--r-- | include/clang/AST/StmtObjC.h | 39 | ||||
-rw-r--r-- | include/clang/Basic/StmtNodes.td | 2 | ||||
-rw-r--r-- | lib/AST/Expr.cpp | 287 | ||||
-rw-r--r-- | lib/AST/ExprCXX.cpp | 202 | ||||
-rw-r--r-- | lib/AST/ExprClassification.cpp | 1 | ||||
-rw-r--r-- | lib/AST/ExprConstant.cpp | 1 | ||||
-rw-r--r-- | lib/AST/ItaniumMangle.cpp | 1 | ||||
-rw-r--r-- | lib/AST/Stmt.cpp | 220 | ||||
-rw-r--r-- | lib/AST/StmtPrinter.cpp | 4 | ||||
-rw-r--r-- | lib/CodeGen/CGStmt.cpp | 1 | ||||
-rw-r--r-- | lib/Sema/TreeTransform.h | 8 | ||||
-rw-r--r-- | lib/StaticAnalyzer/Checkers/ExprEngine.cpp | 1 | ||||
-rw-r--r-- | tools/libclang/CXCursor.cpp | 1 |
20 files changed, 438 insertions, 934 deletions
diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 8c28d52f49..2977d75f30 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -54,8 +54,6 @@ typedef llvm::SmallVector<CXXBaseSpecifier*, 4> CXXCastPath; class Expr : public Stmt { QualType TR; - virtual void ANCHOR(); // key function. - protected: Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK, bool TD, bool VD, bool ContainsUnexpandedParameterPack) : Stmt(SC) { @@ -138,14 +136,9 @@ public: ExprBits.ContainsUnexpandedParameterPack = PP; } - /// SourceLocation tokens are not useful in isolation - they are low level - /// value objects created/interpreted by SourceManager. We assume AST - /// clients will have a pointer to the respective SourceManager. - virtual SourceRange getSourceRange() const = 0; - /// getExprLoc - Return the preferred location for the arrow when diagnosing /// a problem with a generic expression. - virtual SourceLocation getExprLoc() const { return getLocStart(); } + SourceLocation getExprLoc() const; /// isUnusedResultAWarning - Return true if this immediate expression should /// be warned about if the result is unused. If so, fill in Loc and Ranges @@ -682,7 +675,7 @@ public: SourceLocation getLocation() const { return Loc; } void setLocation(SourceLocation L) { Loc = L; } - virtual SourceRange getSourceRange() const; + SourceRange getSourceRange() const; /// \brief Determine whether this declaration reference was preceded by a /// C++ nested-name-specifier, e.g., \c N::foo. @@ -786,8 +779,7 @@ public: static bool classof(const DeclRefExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { return child_range(); } friend class ASTStmtReader; friend class ASTStmtWriter; @@ -827,7 +819,7 @@ public: static std::string ComputeName(IdentType IT, const Decl *CurrentDecl); - virtual SourceRange getSourceRange() const { return SourceRange(Loc); } + SourceRange getSourceRange() const { return SourceRange(Loc); } static bool classof(const Stmt *T) { return T->getStmtClass() == PredefinedExprClass; @@ -835,8 +827,7 @@ public: static bool classof(const PredefinedExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { return child_range(); } }; /// \brief Used by IntegerLiteral/FloatingLiteral to store the numeric without @@ -913,7 +904,7 @@ public: static IntegerLiteral *Create(ASTContext &C, EmptyShell Empty); llvm::APInt getValue() const { return Num.getValue(); } - virtual SourceRange getSourceRange() const { return SourceRange(Loc); } + SourceRange getSourceRange() const { return SourceRange(Loc); } /// \brief Retrieve the location of the literal. SourceLocation getLocation() const { return Loc; } @@ -927,8 +918,7 @@ public: static bool classof(const IntegerLiteral *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { return child_range(); } }; class CharacterLiteral : public Expr { @@ -949,7 +939,7 @@ public: SourceLocation getLocation() const { return Loc; } bool isWide() const { return IsWide; } - virtual SourceRange getSourceRange() const { return SourceRange(Loc); } + SourceRange getSourceRange() const { return SourceRange(Loc); } unsigned getValue() const { return Value; } @@ -963,8 +953,7 @@ public: static bool classof(const CharacterLiteral *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { return child_range(); } }; class FloatingLiteral : public Expr { @@ -1005,7 +994,7 @@ public: SourceLocation getLocation() const { return Loc; } void setLocation(SourceLocation L) { Loc = L; } - virtual SourceRange getSourceRange() const { return SourceRange(Loc); } + SourceRange getSourceRange() const { return SourceRange(Loc); } static bool classof(const Stmt *T) { return T->getStmtClass() == FloatingLiteralClass; @@ -1013,8 +1002,7 @@ public: static bool classof(const FloatingLiteral *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { return child_range(); } }; /// ImaginaryLiteral - We support imaginary integer and floating point literals, @@ -1038,15 +1026,14 @@ public: Expr *getSubExpr() { return cast<Expr>(Val); } void setSubExpr(Expr *E) { Val = E; } - virtual SourceRange getSourceRange() const { return Val->getSourceRange(); } + SourceRange getSourceRange() const { return Val->getSourceRange(); } static bool classof(const Stmt *T) { return T->getStmtClass() == ImaginaryLiteralClass; } static bool classof(const ImaginaryLiteral *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { return child_range(&Val, &Val+1); } }; /// StringLiteral - This represents a string literal expression, e.g. "foo" @@ -1139,7 +1126,7 @@ public: tokloc_iterator tokloc_begin() const { return TokLocs; } tokloc_iterator tokloc_end() const { return TokLocs+NumConcatenated; } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SourceRange(TokLocs[0], TokLocs[NumConcatenated-1]); } static bool classof(const Stmt *T) { @@ -1148,8 +1135,7 @@ public: static bool classof(const StringLiteral *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { return child_range(); } }; /// ParenExpr - This represents a parethesized expression, e.g. "(1)". This @@ -1173,7 +1159,7 @@ public: Expr *getSubExpr() { return cast<Expr>(Val); } void setSubExpr(Expr *E) { Val = E; } - virtual SourceRange getSourceRange() const { return SourceRange(L, R); } + SourceRange getSourceRange() const { return SourceRange(L, R); } /// \brief Get the location of the left parentheses '('. SourceLocation getLParen() const { return L; } @@ -1189,8 +1175,7 @@ public: static bool classof(const ParenExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { return child_range(&Val, &Val+1); } }; @@ -1271,13 +1256,13 @@ public: /// the given unary opcode. static OverloadedOperatorKind getOverloadedOperator(Opcode Opc); - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { if (isPostfix()) return SourceRange(Val->getLocStart(), Loc); else return SourceRange(Loc, Val->getLocEnd()); } - virtual SourceLocation getExprLoc() const { return Loc; } + SourceLocation getExprLoc() const { return Loc; } static bool classof(const Stmt *T) { return T->getStmtClass() == UnaryOperatorClass; @@ -1285,8 +1270,7 @@ public: static bool classof(const UnaryOperator *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { return child_range(&Val, &Val+1); } }; /// OffsetOfExpr - [C99 7.17] - This represents an expression of the form @@ -1473,7 +1457,7 @@ public: return NumExprs; } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SourceRange(OperatorLoc, RParenLoc); } @@ -1484,8 +1468,12 @@ public: static bool classof(const OffsetOfExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { + Stmt **begin = + reinterpret_cast<Stmt**>(reinterpret_cast<OffsetOfNode*>(this + 1) + + NumComps); + return child_range(begin, begin + NumExprs); + } }; /// SizeOfAlignOfExpr - [C99 6.5.3.4] - This is for sizeof/alignof, both of @@ -1565,7 +1553,7 @@ public: SourceLocation getRParenLoc() const { return RParenLoc; } void setRParenLoc(SourceLocation L) { RParenLoc = L; } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SourceRange(OpLoc, RParenLoc); } @@ -1575,8 +1563,7 @@ public: static bool classof(const SizeOfAlignOfExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children(); }; //===----------------------------------------------------------------------===// @@ -1639,14 +1626,14 @@ public: return cast<Expr>(getRHS()->getType()->isIntegerType() ? getRHS():getLHS()); } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SourceRange(getLHS()->getLocStart(), RBracketLoc); } SourceLocation getRBracketLoc() const { return RBracketLoc; } void setRBracketLoc(SourceLocation L) { RBracketLoc = L; } - virtual SourceLocation getExprLoc() const { return getBase()->getExprLoc(); } + SourceLocation getExprLoc() const { return getBase()->getExprLoc(); } static bool classof(const Stmt *T) { return T->getStmtClass() == ArraySubscriptExprClass; @@ -1654,8 +1641,9 @@ public: static bool classof(const ArraySubscriptExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { + return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); + } }; @@ -1775,7 +1763,7 @@ public: SourceLocation getRParenLoc() const { return RParenLoc; } void setRParenLoc(SourceLocation L) { RParenLoc = L; } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SourceRange(getCallee()->getLocStart(), RParenLoc); } @@ -1786,8 +1774,10 @@ public: static bool classof(const CallExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { + return child_range(&SubExprs[0], + &SubExprs[0]+NumArgs+getNumPreArgs()+PREARGS_START); + } }; /// MemberExpr - [C99 6.5.2.3] Structure and Union Members. X->F and X.F. @@ -2007,7 +1997,7 @@ public: SourceLocation getMemberLoc() const { return MemberLoc; } void setMemberLoc(SourceLocation L) { MemberLoc = L; } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { // If we have an implicit base (like a C++ implicit this), // make sure not to return its location SourceLocation EndLoc = (HasExplicitTemplateArgumentList) @@ -2019,7 +2009,7 @@ public: return SourceRange(BaseLoc, EndLoc); } - virtual SourceLocation getExprLoc() const { return MemberLoc; } + SourceLocation getExprLoc() const { return MemberLoc; } static bool classof(const Stmt *T) { return T->getStmtClass() == MemberExprClass; @@ -2027,8 +2017,7 @@ public: static bool classof(const MemberExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { return child_range(&Base, &Base+1); } friend class ASTReader; friend class ASTStmtWriter; @@ -2073,7 +2062,7 @@ public: TypeSourceInfo *getTypeSourceInfo() const { return TInfo; } void setTypeSourceInfo(TypeSourceInfo* tinfo) { TInfo = tinfo; } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { // FIXME: Init should never be null. if (!Init) return SourceRange(); @@ -2088,8 +2077,7 @@ public: static bool classof(const CompoundLiteralExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { return child_range(&Init, &Init+1); } }; /// CastExpr - Base class for type casts, including both implicit @@ -2228,8 +2216,7 @@ public: static bool classof(const CastExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { return child_range(&Op, &Op+1); } }; /// ImplicitCastExpr - Allows us to explicitly represent implicit type @@ -2277,7 +2264,7 @@ public: static ImplicitCastExpr *CreateEmpty(ASTContext &Context, unsigned PathSize); - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return getSubExpr()->getSourceRange(); } @@ -2367,7 +2354,7 @@ public: SourceLocation getRParenLoc() const { return RPLoc; } void setRParenLoc(SourceLocation L) { RPLoc = L; } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SourceRange(LPLoc, getSubExpr()->getSourceRange().getEnd()); } static bool classof(const Stmt *T) { @@ -2436,7 +2423,7 @@ public: Expr *getRHS() const { return cast<Expr>(SubExprs[RHS]); } void setRHS(Expr *E) { SubExprs[RHS] = E; } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SourceRange(getLHS()->getLocStart(), getRHS()->getLocEnd()); } @@ -2503,8 +2490,9 @@ public: static bool classof(const BinaryOperator *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { + return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); + } protected: BinaryOperator(Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, @@ -2636,7 +2624,7 @@ public: SourceLocation getColonLoc() const { return ColonLoc; } void setColonLoc(SourceLocation L) { ColonLoc = L; } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SourceRange(getCond()->getLocStart(), getRHS()->getLocEnd()); } static bool classof(const Stmt *T) { @@ -2645,8 +2633,9 @@ public: static bool classof(const ConditionalOperator *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { + return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); + } }; /// AddrLabelExpr - The GNU address of label extension, representing &&label. @@ -2668,7 +2657,7 @@ public: SourceLocation getLabelLoc() const { return LabelLoc; } void setLabelLoc(SourceLocation L) { LabelLoc = L; } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SourceRange(AmpAmpLoc, LabelLoc); } @@ -2681,8 +2670,7 @@ public: static bool classof(const AddrLabelExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { return child_range(); } }; /// StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}). @@ -2709,7 +2697,7 @@ public: const CompoundStmt *getSubStmt() const { return cast<CompoundStmt>(SubStmt); } void setSubStmt(CompoundStmt *S) { SubStmt = S; } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SourceRange(LParenLoc, RParenLoc); } @@ -2724,8 +2712,7 @@ public: static bool classof(const StmtExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { return child_range(&SubStmt, &SubStmt+1); } }; @@ -2760,7 +2747,7 @@ public: SourceLocation getRParenLoc() const { return RParenLoc; } void setRParenLoc(SourceLocation L) { RParenLoc = L; } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SourceRange(BuiltinLoc, RParenLoc); } static bool classof(const Stmt *T) { @@ -2794,8 +2781,9 @@ public: } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { + return child_range(&SubExprs[0], &SubExprs[0]+NumExprs); + } }; /// ChooseExpr - GNU builtin-in function __builtin_choose_expr. @@ -2851,7 +2839,7 @@ public: SourceLocation getRParenLoc() const { return RParenLoc; } void setRParenLoc(SourceLocation L) { RParenLoc = L; } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SourceRange(BuiltinLoc, RParenLoc); } static bool classof(const Stmt *T) { @@ -2860,8 +2848,9 @@ public: static bool classof(const ChooseExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { + return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR); + } }; /// GNUNullExpr - Implements the GNU __null extension, which is a name @@ -2886,7 +2875,7 @@ public: SourceLocation getTokenLocation() const { return TokenLoc; } void setTokenLocation(SourceLocation L) { TokenLoc = L; } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SourceRange(TokenLoc); } static bool classof(const Stmt *T) { @@ -2895,8 +2884,7 @@ public: static bool classof(const GNUNullExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { return child_range(); } }; /// VAArgExpr, used for the builtin function __builtin_va_arg. @@ -2931,7 +2919,7 @@ public: SourceLocation getRParenLoc() const { return RParenLoc; } void setRParenLoc(SourceLocation L) { RParenLoc = L; } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SourceRange(BuiltinLoc, RParenLoc); } static bool classof(const Stmt *T) { @@ -2940,8 +2928,7 @@ public: static bool classof(const VAArgExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { return child_range(&Val, &Val+1); } }; /// @brief Describes an C or C++ initializer list. @@ -3080,7 +3067,7 @@ public: HadArrayRangeDesignator = ARD; } - virtual SourceRange getSourceRange() const; + SourceRange getSourceRange() const; static bool classof(const Stmt *T) { return T->getStmtClass() == InitListExprClass; @@ -3088,8 +3075,10 @@ public: static bool classof(const InitListExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { + if (InitExprs.empty()) return child_range(); + return child_range(&InitExprs[0], &InitExprs[0] + InitExprs.size()); + } typedef InitExprsTy::iterator iterator; typedef InitExprsTy::const_iterator const_iterator; @@ -3390,7 +3379,7 @@ public: void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First, const Designator *Last); - virtual SourceRange getSourceRange() const; + SourceRange getSourceRange() const; static bool classof(const Stmt *T) { return T->getStmtClass() == DesignatedInitExprClass; @@ -3398,8 +3387,10 @@ public: static bool classof(const DesignatedInitExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { + Stmt **begin = reinterpret_cast<Stmt**>(this + 1); + return child_range(begin, begin + NumSubExprs); + } }; /// \brief Represents an implicitly-generated value initialization of @@ -3425,13 +3416,12 @@ public: } static bool classof(const ImplicitValueInitExpr *) { return true; } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SourceRange(); } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { return child_range(); } }; @@ -3464,7 +3454,7 @@ public: SourceLocation getLParenLoc() const { return LParenLoc; } SourceLocation getRParenLoc() const { return RParenLoc; } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SourceRange(LParenLoc, RParenLoc); } static bool classof(const Stmt *T) { @@ -3473,8 +3463,9 @@ public: static bool classof(const ParenListExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { + return child_range(&Exprs[0], &Exprs[0]+NumExprs); + } friend class ASTStmtReader; friend class ASTStmtWriter; @@ -3531,7 +3522,7 @@ public: /// aggregate Constant of ConstantInt(s). void getEncodedElementAccess(llvm::SmallVectorImpl<unsigned> &Elts) const; - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SourceRange(getBase()->getLocStart(), AccessorLoc); } @@ -3545,8 +3536,7 @@ public: static bool classof(const ExtVectorElementExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { return child_range(&Base, &Base+1); } }; @@ -3573,7 +3563,7 @@ public: const Stmt *getBody() const; Stmt *getBody(); - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SourceRange(getCaretLocation(), getBody()->getLocEnd()); } @@ -3586,8 +3576,7 @@ public: static bool classof(const BlockExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { return child_range(); } }; /// BlockDeclRefExpr - A reference to a local variable declared in an @@ -3613,7 +3602,7 @@ public: SourceLocation getLocation() const { return Loc; } void setLocation(SourceLocation L) { Loc = L; } - virtual SourceRange getSourceRange() const { return SourceRange(Loc); } + SourceRange getSourceRange() const { return SourceRange(Loc); } bool isByRef() const { return IsByRef; } void setByRef(bool BR) { IsByRef = BR; } @@ -3627,8 +3616,7 @@ public: static bool classof(const BlockDeclRefExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { return child_range(); } }; /// OpaqueValueExpr - An expression referring to an opaque object of a @@ -3654,9 +3642,8 @@ public: /// \brief Retrieve the location of this expression. SourceLocation getLocation() const { return Loc; } - virtual SourceRange getSourceRange() const; - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + SourceRange getSourceRange() const { return Loc; } + child_range children() { return child_range(); } static bool classof(const Stmt *T) { return T->getStmtClass() == OpaqueValueExprClass; diff --git a/include/clang/AST/ExprCXX.h b/include/clang/AST/ExprCXX.h index c0e35e3c89..719001aec6 100644 --- a/include/clang/AST/ExprCXX.h +++ b/include/clang/AST/ExprCXX.h @@ -71,7 +71,7 @@ public: /// bracket. SourceLocation getOperatorLoc() const { return getRParenLoc(); } - virtual SourceRange getSourceRange() const; + SourceRange getSourceRange() const; static bool classof(const Stmt *T) { return T->getStmtClass() == CXXOperatorCallExprClass; @@ -108,7 +108,7 @@ public: /// FIXME: Returns 0 for member pointer call exprs. CXXRecordDecl *getRecordDecl(); - virtual SourceRange getSourceRange() const; + SourceRange getSourceRange() const; static bool classof(const Stmt *T) { return T->getStmtClass() == CXXMemberCallExprClass; @@ -151,7 +151,7 @@ public: /// \brief Retrieve the location of the closing parenthesis. SourceLocation getRParenLoc() const { return RParenLoc; } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SourceRange(Loc, RParenLoc); } static bool classof(const Stmt *T) { @@ -306,7 +306,7 @@ public: bool getValue() const { return Value; } void setValue(bool V) { Value = V; } - virtual SourceRange getSourceRange() const { return SourceRange(Loc); } + SourceRange getSourceRange() const { return SourceRange(Loc); } SourceLocation getLocation() const { return Loc; } void setLocation(SourceLocation L) { Loc = L; } @@ -317,8 +317,7 @@ public: static bool classof(const CXXBoolLiteralExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { return child_range(); } }; /// CXXNullPtrLiteralExpr - [C++0x 2.14.7] C++ Pointer Literal @@ -333,7 +332,7 @@ public: explicit CXXNullPtrLiteralExpr(EmptyShell Empty) : Expr(CXXNullPtrLiteralExprClass, Empty) { } - virtual SourceRange getSourceRange() const { return SourceRange(Loc); } + SourceRange getSourceRange() const { return SourceRange(Loc); } SourceLocation getLocation() const { return Loc; } void setLocation(SourceLocation L) { Loc = L; } @@ -343,8 +342,7 @@ public: } static bool classof(const CXXNullPtrLiteralExpr *) { return true; } - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { return child_range(); } }; /// CXXTypeidExpr - A C++ @c typeid expression (C++ [expr.typeid]), which gets @@ -411,7 +409,7 @@ public: Operand = E; } - virtual SourceRange getSourceRange() const { return Range; } + SourceRange getSourceRange() const { return Range; } void setSourceRange(SourceRange R) { Range = R; } static bool classof(const Stmt *T) { @@ -420,8 +418,11 @@ public: static bool classof(const CXXTypeidExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { + if (isTypeOperand()) return child_range(); + Stmt **begin = reinterpret_cast<Stmt**>(&Operand); + return child_range(begin, begin + 1); + } }; /// CXXUuidofExpr - A microsoft C++ @c __uuidof expression, which gets @@ -481,7 +482,7 @@ public: Operand = E; } - virtual SourceRange getSourceRange() const { return Range; } + SourceRange getSourceRange() const { return Range; } void setSourceRange(SourceRange R) { Range = R; } static bool classof(const Stmt *T) { @@ -490,8 +491,11 @@ public: static bool classof(const CXXUuidofExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { + if (isTypeOperand()) return child_range(); + Stmt **begin = reinterpret_cast<Stmt**>(&Operand); + return child_range(begin, begin + 1); + } }; /// CXXThisExpr - Represents the "this" expression in C++, which is a @@ -523,7 +527,7 @@ public: SourceLocation getLocation() const { return Loc; } void setLocation(SourceLocation L) { Loc = L; } - virtual SourceRange getSourceRange() const { return SourceRange(Loc); } + SourceRange getSourceRange() const { return SourceRange(Loc); } bool isImplicit() const { return Implicit; } void setImplicit(bool I) { Implicit = I; } @@ -534,8 +538,7 @@ public: static bool classof(const CXXThisExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { return child_range(); } }; /// CXXThrowExpr - [C++ 15] C++ Throw Expression. This handles @@ -562,7 +565,7 @@ public: SourceLocation getThrowLoc() const { return ThrowLoc; } void setThrowLoc(SourceLocation L) { ThrowLoc = L; } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { if (getSubExpr() == 0) return SourceRange(ThrowLoc, ThrowLoc); return SourceRange(ThrowLoc, getSubExpr()->getSourceRange().getEnd()); @@ -574,8 +577,9 @@ public: static bool classof(const CXXThrowExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { + return child_range(&Op, Op ? &Op+1 : &Op); + } }; /// CXXDefaultArgExpr - C++ [dcl.fct.default]. This wraps up a @@ -649,7 +653,7 @@ public: /// used. SourceLocation getUsedLocation() const { return Loc; } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { // Default argument expressions have no representation in the // source, so they have an empty source range. return SourceRange(); @@ -661,8 +665,7 @@ public: static bool classof(const CXXDefaultArgExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { return child_range(); } friend class ASTStmtReader; friend class ASTStmtWriter; @@ -724,7 +727,7 @@ public: Expr *getSubExpr() { return cast<Expr>(SubExpr); } void setSubExpr(Expr *E) { SubExpr = E; } - virtual SourceRange getSourceRange() const { + SourceRange getSourceRange() const { return SubExpr->getSourceRange(); } @@ -735,8 +738,7 @@ public: static bool classof(const CXXBindTemporaryExpr *) { return true; } // Iterators - virtual child_iterator child_begin(); - virtual child_iterator child_end(); + child_range children() { return child_range(&SubExpr, &SubExpr + 1); } }; /// CXXConstructExpr - Represents a call to a C++ constructor. @@ -842,7 +844,7 @@ public: Args[Arg] = ArgExpr; } - virtual SourceRange getSourceRange() const; + SourceRange getSourceRange() const; SourceRange getParenRange() const { return ParenRange; } static bool classof(const Stmt *T) { |