[cfe-dev] Getting the Bindings of MatchFinder::MatchResult

Jens Weller JensWeller at gmx.de
Fri Aug 17 12:02:28 PDT 2012


Hi,

wasn't sure how to name this one, I have a nice idea:
Building a Counting/Stats/Reporting Callback for ast_matchers.

Background: I think this would be kind of useful, beeing able to run matchers against a class that can report what places in code are found. Without changing them.
This gives me as a Tool Author the option of displaying to the user, where changes will be made to the code, or maybe even what changes.

I thought this is an easy one, and once I'm done, I'll post it to the list.
Well, counting is easy. But actually I want to know, where are those changes, which Files are affected. So, I'd like to have an vector<string> to record all found places.

Now, as this Reporting Callback runs against matchers it does not know, and as far as I've understood, the Bindings of BoundNodes are userdefined strings. Which aren't exposed to me. I can query them, but actually I'd need in this case either access to them, or, maybe even better, some exposed information, maybe SourceLocation start,end would be already enough. I'd like to be able to report things like File, FileLocation (line, column) etc.

Would like to hear some thoughts on the idea and possible solutions.

This is my Code sofar:

namespace {
class ReportingCallback : public MatchFinder::MatchCallback {
 public:
    ReportingCallback(){}
  virtual void run(const MatchFinder::MatchResult &Result)
    {
        str.str("");//reset
        const Stmt* stmt = Result.Nodes.getStmtAs<Stmt>("id");
        const Decl* decl = Result.Nodes.getDeclAs<Decl>("id");
       
        str << "Found Match in " << Result.SourceManager->getFilename(Result.SourceManager->?);
        matches.push_back(str.str());
  }
 private:
    std::vector<std::string> matches;
    std::stringstream str;
};
} // end anonymous namespace

kind regards,

Jens Weller



More information about the cfe-dev mailing list