]> granicus.if.org Git - clang/commitdiff
Some changes to ASTLocation's methods
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 6 Jul 2009 21:35:20 +0000 (21:35 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 6 Jul 2009 21:35:20 +0000 (21:35 +0000)
-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

include/clang/Index/ASTLocation.h
lib/Index/ASTLocation.cpp
tools/index-test/index-test.cpp

index ba401da26a1fcf1831e6c13123262156c51cf611..26c3f3128179b403dffc528f025ab8d650f77ebc 100644 (file)
@@ -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);
index 4b95d9d55429eea3576a1dd3acde4773ab1bdc82..3cd657b9b91beb78cd8fd9158230ec8d2d720be2 100644 (file)
@@ -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 << ", ";
index 37ecbd928f32d5937460f94a4201d01eee9bfe9d..c9c08986463a695a1cdd12ec3992ea0d1d64e9fb 100644 (file)
@@ -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<DeclRefExpr>(Node.getStmt()))
       D = RefExpr->getDecl();
   } else {