[Cython] When to run tree transformations
Stefan Behnel
stefan_ml at behnel.de
Sat Mar 15 11:34:33 CET 2008
Hi,
as I suggested before, I think it would be helpful if plugins could tell the
compiler directly when they were to run (without the current -T option). I
think there would at least be an analysis step in addition to the existing
tree processing step for the plugin lifecycle, but the plugin might also need
to run at different times of the compiler lifecycle, and treat different
syntax structures. I see the following lifecycle hooks here:
- pre analyse types
- post analyse types
- pre generate code
- post generate code
I would suggest mapping these to method names in the plugins. You could then write
class MyTransform(Transform):
def pre_analyse_types(self, node, name):
...
instead of the current "process_node()" method.
I could also imagine keeping a set of node types in the plugin that would be
used for selecting appropriate transformations for the current node. In the
transformation example, there is this line
if isinstance(node, Nodes.ForInStatNode) ...
that determines when to run the plugin. If the plugin provided a set of
interesting nodes instead, the infrastructure could store them in a dict
(mapping node types to a list of plugins) and directly select the
transformations that can run on that node. Question in that case: how to deal
with subtypes? Would they be expected to match? Or should the plugin just
specify all node types, including their expected subtypes?
Stefan
More information about the Cython-dev
mailing list