Thanks for all your support. I’m going to respond all your contributions little by little:
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.)
Ok. What I don’t understand quite well is the order in the execution.
- I create a MatchFinder.
- Then, I add two different matchers to the same callback.
- I call run.
My questions are:
- How many times is called the run method? Every time the MatchFinder finds a node to match?
- The object callback I add to MatchFinder is created more than once? When it is deleted? The problem is that I create the object callback with an argument (a constructor method with an argument, not the default constructor) and store it in a variable member. However, when the run method executes, the value of the variable member is lost and I can’t understand the problem.
Sorry, missed the comment in one of your more recent emails. So you basically want all matches by matcher1 to be found before all matchers by matcher2. I think the easiest way to do this is just have two MatchFinder classes. Add matcher1 and its callback to the first MatchFinder and call run(). Add matcher2 and its callback to the second MatchFinder and call run() after the first run() returns. You won’t have to reparse the file but you will have to traverse the AST twice. There’s not much you can do about this given the order you want. However, if the second matcher has no deps on the information collected by matcher1 you could just get away with a single MatchFinder and two callbacks that just store their finds in two vectors which you process after run returns
I’m not sure what order you’re interested in but you can create two match callbacks one to use for each matcher. The callbacks will be called in the order the nodes are found in the tree by doing a depth-first pre-order traversal as is usual for RecursiveASTVisitor. If both matchers match a given node, the callbacks are called in the order they are registered.
What sort of order are you looking for?
I understand what you have explained until you say “two callbacks”. Why could I want to have two different callbacks? Could you explain better “if the second matcher has no deps on the information collected by matcher1”?
What is often faster is to produce a superset of the information needed during the traversal / match phase, and then combine / filter the results after everything’s done…
That is a good solution, I suppose. I will have to study my case more in detail to determine whether this fit my problem or not. But, do you store all that information in global variables or in the callback object?
You can just count how many times your match callback is called and then print that number after run() returns.
Again, my problem is that I don’t $when the match callback is called.
I hope I can end up getting the usage of all this with your help.
El dia 08 may 2013 12:10, Gábor Kozár firstname.lastname@example.org escribió: