<html>
<head></head>
<body>
<p>Sorry, I was clearing the set of bases incorrectly. Effectively, I was also puzzled with this behavior, but I didn't notice my mistake.</p>
<p>Thanks for everything,</p>
<p>Pedro.</p>
<br/>
<div><em>El día 19 nov 2013 15:31, Daniel Jasper <djasper@google.com> escribió:</em></div><blockquote class="replyBlock" style="border-left: 2px solid #000083; margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div dir="ltr"><br /><div class="gmail_extra"><br /><br /><div class="gmail_quote">On Tue, Nov 19, 2013 at 6:11 AM, Pedro Delgado Perez <span dir="ltr"><<a class="cremed" href="mailto:pedro.delgado@uca.es" target="_blank">pedro.delgado@uca.es</a>></span> wrote:<br /><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: #cccccc; border-left-style: solid; padding-left: 1ex;"><div><p>Hi again,</p>
<p>I came across with a problem using this approach. In my message, I made the following question:</p>
<blockquote style="border-left-width: 2px; border-left-style: solid; border-left-color: #000083; margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><p>class HVD : public MatchFinder::MatchCallback {<br /> ...</p>
<p>static bool collect(const CXXRecordDecl *Base, void *OpaqueData) {<br />      HVD *Data = reinterpret_cast<HVD*>(OpaqueData);<br />      Data->Bases.insert(Base);<br />      return true;<br />  }</p>
<p> virtual void run(const MatchFinder::MatchResult &Result) {<br />      ... ....<br />     if (const CXXRecordDecl *FS = Result.Nodes.getNodeAs<clang::CXXRecordDecl>("var")){<br />         if(FS->forallBases(collect, this)){<br />              for(llvm::SmallPtrSet<const CXXRecordDecl*, 4>::const_iterator i = Bases.begin(); i != Bases.end(); i++){<br />                  ... ... <br />              }<br />        }<br />     }<br />  }<br />};</p>
<br/>
<p>1 - To tell you the truth, I have no idea what I have to do with OpaqueData. Is what I put above correct?</p>
</blockquote><p>And you told me:</p>
<blockquote style="border-left-width: 2px; border-left-style: solid; border-left-color: #000083; margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><p>The OpaqueData part seems correct.</p>
</blockquote><p>However, I have found that every class that is inherited from another class is added in the set of base classes, and not only the base classes inherited from the class calling <em>forallBases</em>. To illustrate what I'm saying, here I put an example:</p>
<p>class A;<br />class B: public A;<br />class C;<br />class D: public C;<br />class E: public D;</p>
<p>If I call "E"->forallBases(collect, this), what I want is that the classes C and D are found, but the class A is also being added because it is inherited from B. I guess the problem is in the second parameter passed to forAllBases ("this") or with "HVD *Data = reinterpret_cast<HVD*>(OpaqueData);" inside "collect", but I'm not so expert using these libraries.</p>
</div></blockquote><div>The usage of OpaqueData still seems correct to me and I very much doubt that forallBases behaves in the way you are describing. Look at the implementation:</div><div><a href="http://clang.llvm.org/doxygen/CXXInheritance_8cpp_source.html#l00136">http://clang.llvm.org/doxygen/CXXInheritance_8cpp_source.html#l00136</a></div><div>It basically iterates of all base classes of the class you are passing in and is then recursively called on these. Are you clearing your "Bases" set between callback invocations (e.g. right before the call to forallBases)? </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: #cccccc; border-left-style: solid; padding-left: 1ex;"><div><p>Please, I need some help to finally solve this matter.</p>
<p>Thanks in advance,</p>
<p>Pedro.</p>
<div><em>El día 11 nov 2013 16:43, Daniel Jasper <<a class="cremed" href="mailto:djasper@google.com" target="_blank">djasper@google.com</a>> escribió:</em></div><blockquote style="border-left-width: 2px; border-left-style: solid; border-left-color: #000083; margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div dir="ltr"><br /><div class="gmail_extra"><br /><br /><div class="gmail_quote">On Mon, Nov 11, 2013 at 2:04 AM, Pedro Delgado Perez <span dir="ltr"><<a class="cremed" href="mailto:pedro.delgado@uca.es" target="_blank">pedro.delgado@uca.es</a>></span> wrote:<br /><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: #cccccc; border-left-style: solid; padding-left: 1ex;"><div><p>Well, using as reference what you named of <span style="font-family: Arial,sans-serif;"><span style="white-space: nowrap;"><span style="font-family: Arial,sans-serif;"><span style="white-space: nowrap;">Sema::</span></span>CheckUsingDeclQualifier, </span></span>I tried the following;</p>
<p>DeclarationMatcher I_Matcher = recordDecl().bind("var");</p>
<p>class HVD : public MatchFinder::MatchCallback {<br />public :<br /><br />  llvm::SmallPtrSet<const CXXRecordDecl*, 4> Bases;<br /> <br />  static bool collect(const CXXRecordDecl *Base, void *OpaqueData) {<br />      HVD *Data = reinterpret_cast<HVD*>(OpaqueData);<br />      Data->Bases.insert(Base);<br />      return true;<br />  }<br />  <br />  virtual void run(const MatchFinder::MatchResult &Result) {<br />      ... ....<br />     if (const CXXRecordDecl *FS = Result.Nodes.getNodeAs<clang::CXXRecordDecl>("var")){<br />         if(FS->forallBases(collect, this)){<br />              for(llvm::SmallPtrSet<const CXXRecordDecl*, 4>::const_iterator i = Bases.begin(); i != Bases.end(); i++){<br />                  ... ... <br />              }<br />        }<br />     }<br />  }<br />};</p>
<p>1 - To tell you the truth, I have no idea what I have to do with OpaqueData. Is what I put above correct?</p>
</div></blockquote><div>The OpaqueData part seems correct. </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: #cccccc; border-left-style: solid; padding-left: 1ex;"><div><p>2 - I got an error doing this and I can't understand the problem.</p>
<p>IHD_operator: /home/pedro/clang-llvm/llvm/tools/clang/include/clang/AST/DeclCXX.h:558: const clang::CXXRecordDecl::DefinitionData& clang::CXXRecordDecl::data() const: Assertion `DefinitionData && "queried property of class with no definition"' failed.<br />Stack dump:<br />0.    <eof> parser at end of file</p>
</div></blockquote><div>As per its comment, forallBases needs to be called on a CXXRecordDecl that is a definition (not e.g. a forward declaration or an injected class name). Thus, you will need to ensure that FS->getDefinition() is not NULL and then call it on that.</div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: #cccccc; border-left-style: solid; padding-left: 1ex;"><div><p>3. Once inside the for loop, how can I get each object CXXRecordDecl through <a class="cremed" href="http://llvm.org/docs/doxygen/html/classllvm_1_1SmallPtrSetIterator.html#ac931fc62430140f2cce08d72e5f27c82" target="_blank">SmallPtrSetIterator.</a></p>
</div></blockquote><div>I think you just need to dereference it:</div><div>const CXXRecordDecl *Base = *i;</div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: #cccccc; border-left-style: solid; padding-left: 1ex;"><div><p>Thanks for your time,</p>
<p>Pedro.</p>
</div></blockquote><div>No problem, I hope this helps,</div><div>Daniel</div><div> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: #cccccc; border-left-style: solid; padding-left: 1ex;"><div><div><em>El día 08 nov 2013 18:30, Daniel Jasper <<a class="cremed" href="mailto:djasper@google.com" target="_blank">djasper@google.com</a>> escribió:</em></div><div><div><blockquote style="border-left-width: 2px; border-left-style: solid; border-left-color: #000083; margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div dir="ltr">Yes, sorry, lookupInBases() is what I meant. You'll need forAllBases(). You can pass in a ForallBasesCallback, which is basically a callback function executed for each base class.<div>I have not used this myself, but for an example, look at:</div><div>CXXRecordDecl::isProvablyNotDerivedFrom defined in <span style="white-space: nowrap; font-family: Arial,sans-serif;">lib/AST/CXXInheritance.cpp.</span></div><div><span style="white-space: nowrap; font-family: Arial,sans-serif;"><br /></span></div><div><span style="white-space: nowrap; font-family: Arial,sans-serif;">Also </span><span style="font-family: Arial,sans-serif;"><span style="white-space: nowrap;">lib/Sema/SemaDeclCXX.cpp has an example close to the bottom of Sema::CheckUsingDeclQualifier()</span></span></div><div><span style="font-family: Arial,sans-serif;"><span style="white-space: nowrap;">that collects all of the bases into a SmallPtrSet.</span></span></div></div><div class="gmail_extra"><br /><br /><div class="gmail_quote">On Fri, Nov 8, 2013 at 9:16 AM, Pedro Delgado Perez <span dir="ltr"><<a class="cremed" href="mailto:pedro.delgado@uca.es" target="_blank">pedro.delgado@uca.es</a>></span> wrote:<br /><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: #cccccc; border-left-style: solid; padding-left: 1ex;"><div><p>Hi,</p>
<p>Thanks Daniel, I suppose you mean CXXRecordDecl::lookupInBases() instead CXXRecordDecl::findInBases().</p>
<p>Have you ever used one of these methods? I don't understand quite well how can I use them for my purpose. What I need is that, given an object CXXRecordDecl, I can analyze something in particular in each one of its base classes (direct or indirect). Thus, I need to get each one of these classes to process them, but the methods you refer only return a <em>bool</em>.</p>
<p>Could you please show me an example using these methods? Mainly, with respect the arguments passed to these methdos.</p>
<p>Thanks,</p>
<p>Pedro.</p>
<div><em>El día 08 nov 2013 15:32, Daniel Jasper <<a class="cremed" href="mailto:djasper@google.com" target="_blank">djasper@google.com</a>> escribió:</em></div><div><div><blockquote style="border-left-width: 2px; border-left-style: solid; border-left-color: #000083; margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div dir="ltr">Take a look at CXXRecordDecl::forallBases() and CXXRecordDecl::findInBases(). Dependent on what you want to do, one of them might do what you need.<div>Cheers,<br />Daniel</div></div><div class="gmail_extra"><br /><br /><div class="gmail_quote">On Fri, Nov 8, 2013 at 2:39 AM, Pedro Delgado Perez <span dir="ltr"><<a class="cremed" href="mailto:pedro.delgado@uca.es" target="_blank">pedro.delgado@uca.es</a>></span> wrote:<br /><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: #cccccc; border-left-style: solid; padding-left: 1ex;"><div><p>Hello,</p>
<p>Please, I need some help with an issue I noticed a few days ago and I am not able to solve.</p>
<p>To illustrate my problem, I show this piece of code:</p>
<p>class A{<br />    public:<br />        A(): a(1) {};<br />        int a;<br />};<br /><br />class B: public A{<br />    public:<br />        B(): b(2){};<br />        int b;<br />};<br /><br />class C: public B{<br />    public:<br />        C(): c(3){};<br />        int b;<br />        int a;<br />};</p>
<p>We have three classes, where:<br />B  inherits directly from A<br />C  inherits directly from B and INDIRECTLY from A</p>
<p>Using CXXRecordDecl::base_class_iterator, the classes indirectly inherited are not visited. Please, can someone explain me how to take into account these indirectly inherited base classes? I've been thinking on recursion (use base_class_iterator on each class directly inherited), but I'm sure there should be another simpler way to do this.</p>
<p>Thanks in advance,</p>
<p>Pedro.</p>
</div><br/>
<p>_______________________________________________<br />cfe-dev mailing list<br /><a class="cremed" href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a></p>
</blockquote></div></div><p><a class="cremed" href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a></p>
</blockquote></div></div></div></blockquote></div><br/>
</div></blockquote></div></div></div></blockquote></div><br/>
</div></div></blockquote></div></blockquote></div><br/>
</div></div></blockquote>
</body>
</html>