]> granicus.if.org Git - clang/commitdiff
Add getName() method to Entity.
authorZhongxing Xu <xuzhongxing@gmail.com>
Wed, 15 Jul 2009 04:39:21 +0000 (04:39 +0000)
committerZhongxing Xu <xuzhongxing@gmail.com>
Wed, 15 Jul 2009 04:39:21 +0000 (04:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@75740 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Index/Entity.h
lib/Index/Entity.cpp

index 8caaeb870fc95ae7f893c17ec163a707b891085e..e65412cbf5e8422b673369d0d97f9d891f383899 100644 (file)
@@ -43,6 +43,9 @@ public:
   /// \brief Find the Decl that can be referred to by this entity.
   Decl *getDecl(ASTContext &AST);
 
+  /// \brief Get the Decl's name.
+  const char *getName(ASTContext &Ctx);
+
   /// \brief Get an Entity associated with the given Decl.
   /// \returns Null if an Entity cannot refer to this Decl.
   static Entity *get(Decl *D, Program &Prog);
index 2620f88a9585bd96b7df4d3c3f8d4302d2b2480f..520d189826aa5a85a306df641d99522c863387d7 100644 (file)
@@ -123,6 +123,13 @@ Decl *Entity::getDecl(ASTContext &AST) {
   return 0; // Failed to find a decl using this Entity.
 }
 
+const char *Entity::getName(ASTContext &Ctx) {
+  if (const NamedDecl *ND = dyn_cast_or_null<NamedDecl>(getDecl(Ctx))) {
+    return ND->getNameAsCString();
+  }
+  return 0;
+}
+
 /// \brief Get an Entity associated with the given Decl.
 /// \returns Null if an Entity cannot refer to this Decl.
 Entity *Entity::get(Decl *D, Program &Prog) {