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 ba401da..26c3f31 100644
--- a/include/clang/Index/ASTLocation.h
+++ b/include/clang/Index/ASTLocation.h
@@ -23,6 +23,7 @@
 namespace clang {
   class Decl;
   class Stmt;
+  class SourceRange;
 
 namespace idx {
 
@@ -54,7 +55,10 @@
 
   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 4b95d9d..3cd657b 100644
--- a/lib/Index/ASTLocation.cpp
+++ b/lib/Index/ASTLocation.cpp
@@ -66,6 +66,10 @@
   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 @@
 
   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 37ecbd9..c9c0898 100644
--- a/tools/index-test/index-test.cpp
+++ b/tools/index-test/index-test.cpp
@@ -152,7 +152,7 @@
   assert(Node.isValid());
 
   Decl *D = 0;
-  if (Node.hasStmt()) {
+  if (Node.isStmt()) {
     if (DeclRefExpr *RefExpr = dyn_cast<DeclRefExpr>(Node.getStmt()))
       D = RefExpr->getDecl();
   } else {