From: Argyrios Kyrtzidis Date: Mon, 6 Jul 2009 21:35:20 +0000 (+0000) Subject: Some changes to ASTLocation's methods X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=755c6b42154e7c2225d973babf84eb2587576bcd;p=clang Some changes to ASTLocation's methods -Change hasStmt() to isStmt() -Add isDecl() -Add getSourceRange() git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74862 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Index/ASTLocation.h b/include/clang/Index/ASTLocation.h index ba401da26a..26c3f31281 100644 --- a/include/clang/Index/ASTLocation.h +++ b/include/clang/Index/ASTLocation.h @@ -23,6 +23,7 @@ namespace llvm { namespace clang { class Decl; class Stmt; + class SourceRange; namespace idx { @@ -54,7 +55,10 @@ public: bool isValid() const { return D != 0; } bool isInvalid() const { return !isValid(); } - bool hasStmt() const { return Stm != 0; } + bool isDecl() const { return isValid() && Stm == 0; } + bool isStmt() const { return isValid() && Stm != 0; } + + SourceRange getSourceRange() const; /// \brief Checks that D is the immediate Decl parent of Node. static bool isImmediateParent(Decl *D, Stmt *Node); diff --git a/lib/Index/ASTLocation.cpp b/lib/Index/ASTLocation.cpp index 4b95d9d554..3cd657b9b9 100644 --- a/lib/Index/ASTLocation.cpp +++ b/lib/Index/ASTLocation.cpp @@ -66,6 +66,10 @@ bool ASTLocation::isImmediateParent(Decl *D, Stmt *Node) { return D == FindImmediateParent(D, Node); } +SourceRange ASTLocation::getSourceRange() const { + return isDecl() ? getDecl()->getSourceRange() : getStmt()->getSourceRange(); +} + void ASTLocation::print(llvm::raw_ostream &OS) { assert(isValid() && "ASTLocation is not valid"); @@ -81,8 +85,7 @@ void ASTLocation::print(llvm::raw_ostream &OS) { OS << "] <"; - SourceRange Range = hasStmt() ? getStmt()->getSourceRange() - : getDecl()->getSourceRange(); + SourceRange Range = getSourceRange(); SourceManager &SourceMgr = getDecl()->getASTContext().getSourceManager(); Range.getBegin().print(OS, SourceMgr); OS << ", "; diff --git a/tools/index-test/index-test.cpp b/tools/index-test/index-test.cpp index 37ecbd928f..c9c0898646 100644 --- a/tools/index-test/index-test.cpp +++ b/tools/index-test/index-test.cpp @@ -152,7 +152,7 @@ static void ProcessNode(ASTLocation Node, IndexProvider &IdxProvider) { assert(Node.isValid()); Decl *D = 0; - if (Node.hasStmt()) { + if (Node.isStmt()) { if (DeclRefExpr *RefExpr = dyn_cast(Node.getStmt())) D = RefExpr->getDecl(); } else {