<div dir="ltr"><div dir="ltr">On Wed, 12 Jan 2022 at 10:01, 何宇轩 via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>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</div><div>“it=CXXRecordDecl->bases_begin()---CXXRecordDecl->bases_end()</div><div>it->getBeginLoc().getRawEncoding()”</div><div>to solve the problem.</div><div>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.</div></blockquote><div><br></div><div>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.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div> </div></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><img src="cid:17e4fb78dbc14f20b951" id="gmail-m_-89678556610225717img_insert_164190979400105136720689284733"><div>thank you very much!<br><br></div>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div></div>