[cfe-commits] r75740 - in /cfe/trunk: include/clang/Index/Entity.h lib/Index/Entity.cpp

Zhongxing Xu xuzhongxing at gmail.com
Tue Jul 14 21:39:29 PDT 2009


Author: zhongxingxu
Date: Tue Jul 14 23:39:21 2009
New Revision: 75740

URL: http://llvm.org/viewvc/llvm-project?rev=75740&view=rev
Log:
Add getName() method to Entity.

Modified:
    cfe/trunk/include/clang/Index/Entity.h
    cfe/trunk/lib/Index/Entity.cpp

Modified: cfe/trunk/include/clang/Index/Entity.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/Entity.h?rev=75740&r1=75739&r2=75740&view=diff

==============================================================================
--- cfe/trunk/include/clang/Index/Entity.h (original)
+++ cfe/trunk/include/clang/Index/Entity.h Tue Jul 14 23:39:21 2009
@@ -43,6 +43,9 @@
   /// \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);

Modified: cfe/trunk/lib/Index/Entity.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/Entity.cpp?rev=75740&r1=75739&r2=75740&view=diff

==============================================================================
--- cfe/trunk/lib/Index/Entity.cpp (original)
+++ cfe/trunk/lib/Index/Entity.cpp Tue Jul 14 23:39:21 2009
@@ -123,6 +123,13 @@
   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) {





More information about the cfe-commits mailing list