Getting clang method callback parameters from a callback

I am adapting the Clang tool template (as described here ) to search for a specific method call in my code. To rewrite this call later, I would like to get the type of parameters with which the method was called, as well as the type of object on which the method was called.

I managed to find a connector that calls the following:

class AddListenerPrinter : public MatchFinder::MatchCallback
{
  public :
  virtual void run(const MatchFinder::MatchResult &Result) {
    if (const auto *FS = Result.Nodes.getNodeAs<clang::MemberExpr>("ListeningBound"))
    {
      FS->dump();
    }
  }
};

which prints:

MemberExpr 0x7fb05b07b948 '<bound member function type>' .addListener 0x7fb05b077670
`-MemberExpr 0x7fb05b07b918 'class MyCore' lvalue ->mCore 0x7fb05b078e30
  `-CXXThisExpr 0x7fb05b07b900 'class MyComponent *' this

Now I can’t find a way to get the type of the object on which the method was called (here class MyCore), or the type of the argument of the method (here class MyComponent).

How can i do this?

+4
source share
1 answer

I found the answer by looking at the code for existing matches.

Using matcher = memberCallExpr( callee(methodDecl(hasName("addListener"))) )

CXXMemberCallExpr node. , , :

// FS is the CXXMemberCallExpr
// Prints out the type of x in x.method()
llvm::outs() << FS->getRecordDecl()->getName();

FS->getArg(n).

: CXX, , (, ?), , ASTMatchers.h.

, - .

+4

Source: https://habr.com/ru/post/1527755/


All Articles