ASTMatchers: isVirtual and isOverride

Hi,

You collect information about the matches into e.g. a vector, and you can use the MatchCallback’s onStartOfTranslationUnit to process the previous TU’s matches.

Ok, this also helps, but the problem is that I need to print something when all the nodes have been matched. So, is there a way I can check within onStartOfTranslationUnit() method if we have reached the end? I have just found this:

clang::ast_matchers::MatchFinder::ParsingDoneTestCallback

This is the implementation of the class:

class ParsingDoneTestCallback {

public:
virtual ~ParsingDoneTestCallback();
virtual void run() = 0;
};

Maybe I could redefine the run method. Do you think this may be my solution?

So the matchers run regardless of whether you ever access the bound nodes. What this means is that your run() method will be called for every match, with the appropriate nodes bound to the names you defined. So a MatchResult only contains information about one single match (i.e. a subtree of the AST, if you will). Hope this clears things up.

Um… I’m a bit mixed up at this moment. So, what you are saying is that I can’t control the order the nodes are matched? For me that would be a problem because I need to keep an order in the execution. What I’m trying to explain is that I need all the nodes bound with Matcher1 are treated before the execution of nodes bound with Matcher2 starts.

Thanks,

Pedro.

El dia 07 may 2013 22:10, Gábor Kozár kozargabor@gmail.com escribió:

Hi,

Ok, this also helps, but the problem is that I need to print something when all the nodes have been matched. So, is there a way I can check within onStartOfTranslationUnit() method if we have reached the end? I have just found this:

onStartOfTranslationUnit() is - obviously - called at the start of each TU. I.e. this will be called after the previous TU has been completed, i.e. all nodes in it have been matched.

clang::ast_matchers::MatchFinder::ParsingDoneTestCallback

This is for testing purposes only, it’s not recommended to use it.

So, what you are saying is that I can’t control the order the nodes are matched?

No, you can’t. You’ll have to implement a RecursiveASTVisitor manually if you need this fine control.

What I’m trying to explain is that I need all the nodes bound with Matcher1 are treated before the execution of nodes bound with Matcher2 starts.

You can execute Matcher1 first, and when it returns, you start executing Matcher2. I’m not sure what your problem is exactly. (Of course, this will also mean that you will traverse the whole AST twice, which can potentially be very expensive.)

Gabor