[cfe-commits] r76336 - in /cfe/trunk: include/clang/Index/ASTLocation.h lib/Index/ASTLocation.cpp tools/index-test/index-test.cpp
Argiris Kirtzidis
akyrtzi at gmail.com
Sat Jul 18 14:17:59 PDT 2009
Author: akirtzidis
Date: Sat Jul 18 16:17:58 2009
New Revision: 76336
URL: http://llvm.org/viewvc/llvm-project?rev=76336&view=rev
Log:
Introduce ASTLocation::getReferencedDecl(), for getting the declaration that the ASTLocation references.
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=76336&r1=76335&r2=76336&view=diff
==============================================================================
--- cfe/trunk/include/clang/Index/ASTLocation.h (original)
+++ cfe/trunk/include/clang/Index/ASTLocation.h Sat Jul 18 16:17:58 2009
@@ -58,6 +58,16 @@
bool isDecl() const { return isValid() && Stm == 0; }
bool isStmt() const { return isValid() && Stm != 0; }
+ /// \brief Returns the declaration that this ASTLocation references.
+ ///
+ /// If this points to a Decl, that Decl is returned.
+ /// If this points to an Expr that references a Decl, that Decl is returned,
+ /// otherwise it returns NULL.
+ Decl *getReferencedDecl();
+ const Decl *getReferencedDecl() const {
+ return const_cast<ASTLocation*>(this)->getReferencedDecl();
+ }
+
SourceRange getSourceRange() const;
/// \brief Checks that D is the immediate Decl parent of Node.
Modified: cfe/trunk/lib/Index/ASTLocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/ASTLocation.cpp?rev=76336&r1=76335&r2=76336&view=diff
==============================================================================
--- cfe/trunk/lib/Index/ASTLocation.cpp (original)
+++ cfe/trunk/lib/Index/ASTLocation.cpp Sat Jul 18 16:17:58 2009
@@ -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");
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=76336&r1=76335&r2=76336&view=diff
==============================================================================
--- cfe/trunk/tools/index-test/index-test.cpp (original)
+++ cfe/trunk/tools/index-test/index-test.cpp Sat Jul 18 16:17:58 2009
@@ -141,30 +141,12 @@
}
}
-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;
-}
-
static void ProcessASTLocation(ASTLocation ASTLoc, IndexProvider &IdxProvider) {
assert(ASTLoc.isValid());
- Decl *D = 0;
- if (ASTLoc.isStmt())
- D = getDeclFromExpr(ASTLoc.getStmt());
- else
- D = ASTLoc.getDecl();
-
+ Decl *D = ASTLoc.getReferencedDecl();
if (D == 0) {
- llvm::errs() << "Error: Couldn't get a Decl out of the ASTLocation";
+ llvm::errs() << "Error: Couldn't get a referenced Decl for the ASTLocation";
HadErrors = true;
return;
}
More information about the cfe-commits
mailing list