diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-07-06 21:35:20 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-07-06 21:35:20 +0000 |
commit | 755c6b42154e7c2225d973babf84eb2587576bcd (patch) | |
tree | 1f2e952ec68f69f37524d09c12439ab08e37e52b | |
parent | 8fb3333d45ab3b327766e26310581cacf43fb374 (diff) |
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
-rw-r--r-- | include/clang/Index/ASTLocation.h | 6 | ||||
-rw-r--r-- | lib/Index/ASTLocation.cpp | 7 | ||||
-rw-r--r-- | tools/index-test/index-test.cpp | 2 |
3 files changed, 11 insertions, 4 deletions
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<DeclRefExpr>(Node.getStmt())) D = RefExpr->getDecl(); } else { |