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 | b8020f0833eb99e95c049c19bf3b95957c07e9f7 (patch) | |
tree | 7058bafde0d0de55e2f6b652846735683e7a7a96 | |
parent | b89c4cba7d6d8310bba93fe4da24cf543e63690f (diff) | |
download | bcm5719-llvm-b8020f0833eb99e95c049c19bf3b95957c07e9f7.tar.gz bcm5719-llvm-b8020f0833eb99e95c049c19bf3b95957c07e9f7.zip |
Some changes to ASTLocation's methods
-Change hasStmt() to isStmt()
-Add isDecl()
-Add getSourceRange()
llvm-svn: 74862
-rw-r--r-- | clang/include/clang/Index/ASTLocation.h | 6 | ||||
-rw-r--r-- | clang/lib/Index/ASTLocation.cpp | 7 | ||||
-rw-r--r-- | clang/tools/index-test/index-test.cpp | 2 |
3 files changed, 11 insertions, 4 deletions
diff --git a/clang/include/clang/Index/ASTLocation.h b/clang/include/clang/Index/ASTLocation.h index ba401da26a1..26c3f312817 100644 --- a/clang/include/clang/Index/ASTLocation.h +++ b/clang/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/clang/lib/Index/ASTLocation.cpp b/clang/lib/Index/ASTLocation.cpp index 4b95d9d5542..3cd657b9b91 100644 --- a/clang/lib/Index/ASTLocation.cpp +++ b/clang/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/clang/tools/index-test/index-test.cpp b/clang/tools/index-test/index-test.cpp index 37ecbd928f3..c9c08986463 100644 --- a/clang/tools/index-test/index-test.cpp +++ b/clang/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 { |