On 7 February 2013 11:32, Stefan Behnel <stefan...@behnel.de> wrote:
> Hi,
>
> I finally found the time to refactor the analysis phase.
>
> https://github.com/cython/cython/commit/f9c385e08401ed96b5b0afb8411480037dc772b9
>
> The methods now return a node, which allows them to replace themselves with
> a different implementation.
>
> Note that the relatively large code impact of this change also means that
> you might easily run into merge conflicts with your own local changes, so
> here's how to fix them. The transformation pattern is pretty straight
> forward. The "analyse_types()" method returns "self", unless it wants to
> replace itself, i.e. this
>
>     def analyse_types(self, env):
>         self.index.analyse_types(env)
>
> becomes
>
>     def analyse_types(self, env):
>         self.index = self.index.analyse_types(env)
>         return self
>
> The "analyse_target_types()" method works the same, but because it calls
> "analyse_types()" internally in most cases, it's more likely to look like 
> this:
>
>     def analyse_target_types(self, env):
>         self.analyse_types(env)
>         if self.type.is_pyobject:
>             self.type = py_object_type
>
> which now turns into this:
>
>     def analyse_target_types(self, env):
>         node = self.analyse_types(env)
>         if node.type.is_pyobject:
>             node.type = py_object_type
>         return node
>
> The same pattern obviously applies in the cases where the node needs to be
> replaced in "analyse_types()". It would simply build and return a different
> node. This also allows for in-place coercions of the current node, for 
> example.
>
> With this change in place, we can now start to clean up old hacks like the
> "__class__" replacement in AttributeNode. If anyone wants to give it a try,
> please go ahead. :)
>
> Stefan
> _______________________________________________
> cython-devel mailing list
> cython-devel@python.org
> http://mail.python.org/mailman/listinfo/cython-devel

What, you didn't like overriding __class__? :) That's great work
Stefan! Do you eventually want to move these methods to a visitor, or
do you want to keep them as methods?
_______________________________________________
cython-devel mailing list
cython-devel@python.org
http://mail.python.org/mailman/listinfo/cython-devel

Reply via email to