diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-07-18 21:17:58 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-07-18 21:17:58 +0000 |
commit | dc50c64c13322dd81b10263cbb023fb1f7eae1fd (patch) | |
tree | e6b17761f2ce1cf4151b7798c6888f154d114c20 /lib/Index/ASTLocation.cpp | |
parent | 9b9685dc713679581b3953cd9ece0001b63f551f (diff) |
Introduce ASTLocation::getReferencedDecl(), for getting the declaration that the ASTLocation references.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76336 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Index/ASTLocation.cpp')
-rw-r--r-- | lib/Index/ASTLocation.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/Index/ASTLocation.cpp b/lib/Index/ASTLocation.cpp index d83e0e33f3..84d79363ef 100644 --- a/lib/Index/ASTLocation.cpp +++ b/lib/Index/ASTLocation.cpp @@ -19,6 +19,30 @@ using namespace clang; using namespace idx; +static Decl *getDeclFromExpr(Stmt *E) { + if (DeclRefExpr *RefExpr = dyn_cast<DeclRefExpr>(E)) + return RefExpr->getDecl(); + if (MemberExpr *ME = dyn_cast<MemberExpr>(E)) + return ME->getMemberDecl(); + if (CallExpr *CE = dyn_cast<CallExpr>(E)) + return getDeclFromExpr(CE->getCallee()); + if (CastExpr *CE = dyn_cast<CastExpr>(E)) + return getDeclFromExpr(CE->getSubExpr()); + + return 0; +} + +Decl *ASTLocation::getReferencedDecl() { + if (isInvalid()) + return 0; + if (isDecl()) + return getDecl(); + + assert(getStmt()); + return getDeclFromExpr(getStmt()); +} + + static bool isContainedInStatement(Stmt *Node, Stmt *Parent) { assert(Node && Parent && "Passed null Node or Parent"); |