[cfe-dev] CXXRecordDecl Name

Daniel Dilts diltsman at gmail.com
Tue Jul 1 09:21:36 PDT 2014


If I have this code then everything works.  If I get rid of the forward
declaration, then any method returns an empty string.  Is the forward
declaration mandatory when defining the class like this?

namespace N {
  class BaseClass1;
}
class N::BaseClass1 {
public:
  BaseClass1(int i);
  BaseClass1(const BaseClass1 &right);
  virtual ~BaseClass1();
  BaseClass1 &operator=(const BaseClass1 &right);
}


On Mon, Jun 30, 2014 at 3:35 PM, Reid Kleckner <rnk at google.com> wrote:

> Try getDeclName(), getNameAsString(), or others.  getName() only works if
> the name is a simple identifier:
>
>   /// getName - Get the name of identifier for this declaration as a
> StringRef.
>   /// This requires that the declaration have a name and that it be a
> simple
>   /// identifier.
>   StringRef getName() const {
>     assert(Name.isIdentifier() && "Name is not a simple identifier");
>     return getIdentifier() ? getIdentifier()->getName() : "";
>   }
>
>
>
> On Mon, Jun 30, 2014 at 3:21 PM, Daniel Dilts <diltsman at gmail.com> wrote:
>
>> I am attempting to get the name of a CXXRecordDecl that I have identified
>> with an AST matcher.  I am using Class->getName().str() to get the class
>> name.
>>
>> namespace N {
>> class SomeNonInterface {
>>   virtual void func1() = 0;
>>   virtual void func2() {}
>> };
>> }
>>
>> It works great for the above code.  Gives me "SomeNonInterface" as the
>> name.
>>
>> class N::BaseClass1 {
>> public:
>>   BaseClass1(int i);
>>   BaseClass1(const BaseClass1 &right);
>>   virtual ~BaseClass1();
>>   BaseClass1 &operator=(const BaseClass1 &right);
>> };
>>
>> For the above code it gives me "" as the name.
>>
>> How would I get the class name so that it works in all cases, even if the
>> name in the declaration/definition is namespace qualified?  Or...did I hit
>> a case that isn't legal?
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140701/0713b2f2/attachment.html>


More information about the cfe-dev mailing list