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

Chris Lattner clattner at apple.com
Wed Jul 15 21:44:28 PDT 2009


On Jul 14, 2009, at 9:39 PM, Zhongxing Xu wrote:
> 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.

Hi Zhongxing,

I don't think this is a good idea.  Entity will be getting more  
complicated eventually to support things like objc selectors, C++  
templates, etc.  Eventually we want the ability to turn an Entity into  
a stable string representation (suitable for sticking in a database  
etc) but I don't think this should be called "getName()", it should be  
something like "getStableString()" or something like that.

Argiris, what do you think?

-Chris

>
> 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) {
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list