Matching Indirect base classes

Well, using as reference what you named of Sema::CheckUsingDeclQualifier, I tried the following;

DeclarationMatcher I_Matcher = recordDecl().bind(“var”);

class HVD : public MatchFinder::MatchCallback {
public :

llvm::SmallPtrSet<const CXXRecordDecl*, 4> Bases;

static bool collect(const CXXRecordDecl *Base, void *OpaqueData) {
HVD Data = reinterpret_cast<HVD>(OpaqueData);
Data->Bases.insert(Base);
return true;
}

virtual void run(const MatchFinder::MatchResult &Result) {
… …
if (const CXXRecordDecl FS = Result.Nodes.getNodeAsclang::CXXRecordDecl(“var”)){
if(FS->forallBases(collect, this)){
for(llvm::SmallPtrSet<const CXXRecordDecl
, 4>::const_iterator i = Bases.begin(); i != Bases.end(); i++){
… …
}
}
}
}
};

1 - To tell you the truth, I have no idea what I have to do with OpaqueData. Is what I put above correct?
2 - I got an error doing this and I can’t understand the problem.

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.
Stack dump:
0. parser at end of file

  1. Once inside the for loop, how can I get each object CXXRecordDecl through SmallPtrSetIterator.

Thanks for your time,

Pedro.

El día 08 nov 2013 18:30, Daniel Jasper djasper@google.com escribió:

Well, using as reference what you named of Sema::CheckUsingDeclQualifier,
I tried the following;

DeclarationMatcher I_Matcher = recordDecl().bind("var");

class HVD : public MatchFinder::MatchCallback {
public :

  llvm::SmallPtrSet<const CXXRecordDecl*, 4> Bases;

  static bool collect(const CXXRecordDecl *Base, void *OpaqueData) {
      HVD *Data = reinterpret_cast<HVD*>(OpaqueData);
      Data->Bases.insert(Base);
      return true;
  }

  virtual void run(const MatchFinder::MatchResult &Result) {
      ... ....
     if (const CXXRecordDecl *FS =
Result.Nodes.getNodeAs<clang::CXXRecordDecl>("var")){
         if(FS->forallBases(collect, this)){
              for(llvm::SmallPtrSet<const CXXRecordDecl*,
4>::const_iterator i = Bases.begin(); i != Bases.end(); i++){
                  ... ...
              }
        }
     }
  }
};

1 - To tell you the truth, I have no idea what I have to do with
OpaqueData. Is what I put above correct?

The OpaqueData part seems correct.

2 - I got an error doing this and I can't understand the problem.

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.
Stack dump:
0. <eof> parser at end of file

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.

3. Once inside the for loop, how can I get each object CXXRecordDecl
through SmallPtrSetIterator.<http://llvm.org/docs/doxygen/html/classllvm_1_1SmallPtrSetIterator.html#ac931fc62430140f2cce08d72e5f27c82>

I think you just need to dereference it:

const CXXRecordDecl *Base = *i;

Thanks for your time,

Pedro.

No problem, I hope this helps,
Daniel