From: Abramo Bagnara Date: Wed, 16 Mar 2011 15:08:46 +0000 (+0000) Subject: Added missing methods to get Designators source range. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=24f4674e697fb53587f0e8485e9c6592f7021ef2;p=clang Added missing methods to get Designators source range. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127735 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 23e42768e8..35264b820d 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -3489,6 +3489,12 @@ public: else return getLBracketLoc(); } + SourceLocation getEndLocation() const { + return Kind == FieldDesignator ? getFieldLoc() : getRBracketLoc(); + } + SourceRange getSourceRange() const { + return SourceRange(getStartLocation(), getEndLocation()); + } }; static DesignatedInitExpr *Create(ASTContext &C, Designator *Designators, @@ -3571,6 +3577,8 @@ public: void ExpandDesignator(ASTContext &C, unsigned Idx, const Designator *First, const Designator *Last); + SourceRange getDesignatorsSourceRange() const; + SourceRange getSourceRange() const; static bool classof(const Stmt *T) { diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 9c4444225e..59de3fe6ee 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -2740,6 +2740,14 @@ void DesignatedInitExpr::setDesignators(ASTContext &C, Designators[I] = Desigs[I]; } +SourceRange DesignatedInitExpr::getDesignatorsSourceRange() const { + DesignatedInitExpr *DIE = const_cast(this); + if (size() == 1) + return DIE->getDesignator(0)->getSourceRange(); + return SourceRange(DIE->getDesignator(0)->getStartLocation(), + DIE->getDesignator(size()-1)->getEndLocation()); +} + SourceRange DesignatedInitExpr::getSourceRange() const { SourceLocation StartLoc; Designator &First =