Discussion:
[Synopsis-devel] RewriteVisitor class for source-to-source transformation
francis maes
2009-01-10 19:17:27 UTC
Permalink
* 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:

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.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: RewriteVisitor.h
Url: http://lists.fresco.org/pipermail/synopsis-devel/attachments/20090110/c70fa904/attachment.txt
Stefan Seefeld
2009-01-10 23:56:44 UTC
Permalink
Post by francis maes
* 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
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.
Post by francis maes
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...
Loading...