[cfe-commits] r74862 - in /cfe/trunk: include/clang/Index/ASTLocation.h lib/Index/ASTLocation.cpp tools/index-test/index-test.cpp

Argiris Kirtzidis akyrtzi at gmail.com
Mon Jul 6 14:35:20 PDT 2009


Author: akirtzidis
Date: Mon Jul  6 16:35:20 2009
New Revision: 74862

URL: http://llvm.org/viewvc/llvm-project?rev=74862&view=rev
Log:
Some changes to ASTLocation's methods

-Change hasStmt() to isStmt()
-Add isDecl()
-Add getSourceRange()

Modified:
    cfe/trunk/include/clang/Index/ASTLocation.h
    cfe/trunk/lib/Index/ASTLocation.cpp
    cfe/trunk/tools/index-test/index-test.cpp

Modified: cfe/trunk/include/clang/Index/ASTLocation.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/ASTLocation.h?rev=74862&r1=74861&r2=74862&view=diff

==============================================================================
--- cfe/trunk/include/clang/Index/ASTLocation.h (original)
+++ cfe/trunk/include/clang/Index/ASTLocation.h Mon Jul  6 16:35:20 2009
@@ -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);

Modified: cfe/trunk/lib/Index/ASTLocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/ASTLocation.cpp?rev=74862&r1=74861&r2=74862&view=diff

==============================================================================
--- cfe/trunk/lib/Index/ASTLocation.cpp (original)
+++ cfe/trunk/lib/Index/ASTLocation.cpp Mon Jul  6 16:35:20 2009
@@ -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 << ", ";

Modified: cfe/trunk/tools/index-test/index-test.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/index-test/index-test.cpp?rev=74862&r1=74861&r2=74862&view=diff

==============================================================================
--- cfe/trunk/tools/index-test/index-test.cpp (original)
+++ cfe/trunk/tools/index-test/index-test.cpp Mon Jul  6 16:35:20 2009
@@ -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 {





More information about the cfe-commits mailing list