[cfe-dev] Looking for help on using clang

Richard Smith via cfe-dev cfe-dev at lists.llvm.org
Wed Jan 12 11:18:35 PST 2022


On Wed, 12 Jan 2022 at 10:01, 何宇轩 via cfe-dev <cfe-dev at lists.llvm.org>
wrote:

> Hi, I would like to use clang-tidy to analyze the inheritance relationship
> between classes defined in a c++ file. I was going to use
> “it=CXXRecordDecl->bases_begin()---CXXRecordDecl->bases_end()
> it->getBeginLoc().getRawEncoding()”
> to solve the problem.
> For example, for the graph below, I wanted to first get the location
> encoding of B, assuming it was b, and then when analyzing D, get the base
> location encoding of D which is also the location encoding of B, d. I
> originally thought that b==d,so I can identify a relation between B and D,
> however, this was not the case. So I would like to know if there is any
> other way that I can establish a relationship with its parent class when I
> get the cxxRecordDecl of D.
>

You can use it->getType()->getAsCXXRecordDecl() to find a declaration of
the base class. Then you can use clang::declaresSameEntity to compare
whether that is the same class as B.


>
>
thank you very much!
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20220112/0ca649b4/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 2D37415F at F6290601.E08EDD61.png.jpg
Type: image/jpeg
Size: 5417 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20220112/0ca649b4/attachment.jpg>


More information about the cfe-dev mailing list