> You could have just implemented Callback with process() and created your
> won constructor if that makes it more clear, it wasn't neccessary to
> subclass but, it was there so, ya know. :)
I got that and that wasn't a problem.
> The base class why my design and for all the passes I did, I needed the
> callbacks. See NodeTraversal.travese() I think it is, that is what actually
> calls the callbacks and shouldTravese(), it's in the GCC API.
Actually, process() calls:
NodeTraversal.traverseRoots(compiler, this, externs, root);
Which in turn calls:
traverseBranch(externs, scopeRoot);
Preconditions.checkState(root.getParent() == scopeRoot);
traverseBranch(root, scopeRoot);
I was asking, why should it traverse the most out of external scoped node of
the root and the root itself ?
traverseBranch then call shouldTravese() which may call visit but the doc says:
/**
* Callback for tree-based traversals
*/
public interface Callback {
/**
* Visits a node in pre order (before visiting its children) and decides
* whether this node's children should be traversed. If children are
* traversed, they will be visited by
* {@link #visit(NodeTraversal, Node, Node)} in postorder.<BR>
* Implementations can have side effects (e.g. modifying the parse
* tree).<BR>
* @return whether the children of this node should be visited
*/
boolean shouldTraverse(NodeTraversal nodeTraversal, Node n, Node parent);
/**
* Visits a node in postorder (after its children have been visited).
* A node is visited only if all its parents should be traversed
* ({@link #shouldTraverse(NodeTraversal, Node, Node)}).<BR>
* Implementations can have side effects (e.g. modifying the parse
* tree).<BR>
*/
void visit(NodeTraversal t, Node n, Node parent);
It is where I didn't get the pre / post orders, if shouldTraverse() returns
true, the visit() children is called which if fine too me but in the doc of
visit() they talk about postorder (and I'm lost here): A node is visited only
if all its parents should be traversed, does it mean it will traverse all the
parents ? or "all its parents should have been already traversed" ?
I'm confused, can you explain ?
> JFlex is used to create the RawASDocTokenizer. So yes, if a grammar was
> created for asdoc parsing in antlr, we could get rid of JFlex dependency
> because I think that is the only place it's used.
Good to know !-)
Thanks,
Frédéric THOMAS
----------------------------------------
> Date: Thu, 9 Jul 2015 12:17:04 -0400
> Subject: Re: [FalconJX] Collection Imports branch
> From: [email protected]
> To: [email protected]
>
> On Thu, Jul 9, 2015 at 12:01 PM, Frédéric THOMAS <[email protected]>
> wrote:
>
>>> You're not traversing anything, it just happens that the base class is
>>> abstract and defines callbacks for recursion. In your case you just want
>> a
>>> "processing" compiler pass.
>>>
>>> A plain old compiler pass wouldn't require visiting all nodes, just a
>>> process().
>>>
>>> Don't worry about it, the two you overrode are just stubs.
>>
>> Well, I got I did an override :-) I just was trying to understand the base
>> classes.
>>
>
>
> The base class why my design and for all the passes I did, I needed the
> callbacks. See NodeTraversal.travese() I think it is, that is what actually
> calls the callbacks and shouldTravese(), it's in the GCC API.
>
> You could have just implemented Callback with process() and created your
> won constructor if that makes it more clear, it wasn't neccessary to
> subclass but, it was there so, ya know. :)
>
>
>
>>
>> Anyway, thanks again Mike for your explanations !
>>
>> I will now go back on Falcon starting from the beginning trying to
>> understand the scan / parse phase, even if I understand approximatively how
>> theoretically it should work, it seems a huge thing to me in there, I see
>> JFlex, ANTLR, btw I thought it was possible to do the scan / parse with
>> ANTLR only, am I wrong ? if not why are we using JFlex too ?
>>
>
>
> JFlex is used to create the RawASDocTokenizer. So yes, if a grammar was
> created for asdoc parsing in antlr, we could get rid of JFlex dependency
> because I think that is the only place it's used.
>
> Mike
>
>
>
>>
>> I will try to experiment, even with ANTLR4.x
>>
>> Frédéric THOMAS
>>
>>
>> ----------------------------------------
>>> Date: Thu, 9 Jul 2015 11:25:09 -0400
>>> Subject: Re: [FalconJX] Collection Imports branch
>>> From: [email protected]
>>> To: [email protected]
>>>
>>> You're not traversing anything, it just happens that the base class is
>>> abstract and defines callbacks for recursion. In your case you just want
>> a
>>> "processing" compiler pass.
>>>
>>> A plain old compiler pass wouldn't require visiting all nodes, just a
>>> process().
>>>
>>> Don't worry about it, the two you overrode are just stubs.
>>>
>>> Mike
>>>
>>> On Thu, Jul 9, 2015 at 11:13 AM, Frédéric THOMAS <
>> [email protected]>
>>> wrote:
>>>
>>>>> Other than that, merge/commit it man! thanks, looks good to me, we will
>>>> see
>>>>> if anything else comes up.
>>>>
>>>> Thanks, done !
>>>>
>>>> But I'm still confuse with the pattern:
>>>>
>>>> I didn't get well this thing about pre / post order in the Callback
>>>> interface maybe I didn't get what it means, isn't supposed to be
>> recursive
>>>> descendant only, how does it work ?
>>>> I used process() which traverseRoots of both externs (the most out of
>>>> parent) and the given node, why 2 nodes have to be traversed in the same
>>>> function ?
>>>>
>>>> Frédéric THOMAS
>>>>
>>>>
>>>> ----------------------------------------
>>>>> Date: Wed, 8 Jul 2015 16:46:34 -0400
>>>>> Subject: [FalconJX] Collection Imports branch
>>>>> From: [email protected]
>>>>> To: [email protected]
>>>>>
>>>>> Hey Fred,
>>>>>
>>>>> Couple things;
>>>>>
>>>>> 1. CollectImportsPass
>>>>>
>>>>> Should probably be; (process() only gets called once)
>>>>>
>>>>> @Override
>>>>> public void process(Node externs, Node root)
>>>>> {
>>>>> for (ClassReference reference : model.getClasses())
>>>>> {
>>>>> collectClassImports(reference);
>>>>> }
>>>>>
>>>>> for (FunctionReference reference : model.getFunctions())
>>>>> {
>>>>> collectFunctionImports(reference);
>>>>> }
>>>>> }
>>>>>
>>>>> @Override
>>>>> public boolean shouldTraverse(final NodeTraversal nodeTraversal, final
>>>>> Node n, final Node parent)
>>>>> {
>>>>> return false;
>>>>> }
>>>>>
>>>>> @Override
>>>>> public void visit(final NodeTraversal t, final Node n, final Node
>>>>> parent)
>>>>> {
>>>>> }
>>>>>
>>>>>
>>>>> Other than that, merge/commit it man! thanks, looks good to me, we will
>>>> see
>>>>> if anything else comes up.
>>>>>
>>>>> Mike
>>>>
>>>>
>>
>>