Re: RewriteVisitor class for source-to-source transformation
Stefan Seefeld <[email protected]> Sat, 10 Jan 2009 18:56:44 -0500
| Newsgroups | gmane.comp.documentation.synopsis |
|---|---|
| Message-ID | <[email protected]> |
francis maes wrote:
>>> * New baseclass "RewriteVisitor" whose default implementation clones a
>>> PTree (file RewriteVisitor.h). I use this base class for all the
>>> visitors that perform source-to-source transformation.
>>>
>>>
>> Can you describe in what way the existing Visitor base class isn't generic
>> enough for your needs ?
>>
>>
>
> The RewriteVisitor inherits from the existing Visitor base class. Its
> implementation simply clone the visited PTree, without loosing the
> type of the PTree::Nodes:
>
Oh, so I misundestood. I thought you had to replace (or at least,
modify) the existing PTree::Visitor base class to accomodate for your
needs. Subclassing to add custom behavior like you did is perfectly fine.
> PTree* clone(PTree* tree) {return RewriteVisitor().rewrite(tree);}
>
> In order to perform source-to-source transformation, I inherit from
> RewriteVisitor and override only the visit functions corresponding to
> the nodes that have to be rewritten differently.
>
That sounds good.
Unfortunately, the parser in the S10 branch (and thus, the one part of
all existing Synopsis releases) is not quite standard conformant, and
the node types don't really match the C++ grammar. Thus there is going
to be quite some changes in the PTree API as things evolve. (You may
have a look into the trunk, which is much better already, though it is
still more fragile in its parsing of C++ (as the parser is 'more
standard compliant', it requires type analysis for disambiguation, which
I haven't worked on yet).
Having said that, I'm glad you are exploring source generation, and I'm
looking forward to enhancing Synopsis as we move along.
Don't hesitate to ask for help, report issues, or suggest changes /
additions.
Regards,
Stefan
--
...ich hab' noch einen Koffer in Berlin...