[Cython] [Fwd: Re: Beginner-friendly tickets]
Dag Sverre Seljebotn
dagss at student.matnat.uio.no
Mon Mar 16 09:40:51 CET 2009
Ahh; this was sent to my private address as well and so cython-dev in
its wisdom decided not to send me a copy from the mailing list.
Forwarding my response to the mailing list as well then.
-------- Original Message --------
Subject: Re: [Cython] Beginner-friendly tickets
Date: Mon, 16 Mar 2009 08:23:26 +0100
From: Dag Sverre Seljebotn <dagss at student.matnat.uio.no>
To: Kurt Smith <kwmsmith at gmail.com>
References: <49B783FA.5070309 at student.matnat.uio.no>
<c266a7930903111322i1f62fe74qef7a1dea8de14db4 at mail.gmail.com>
<49B82598.3000303 at student.matnat.uio.no>
<49B8263C.6090706 at student.matnat.uio.no>
<c266a7930903152226k388da7d3m8c1440eef24cdf6e at mail.gmail.com>
Kurt Smith wrote:
> Thanks for the guidance -- I'm making progress but I can't figure out one issue:
>
> when I add the following method to AnalyzeDeclarationsTransform
> everything works as expected:
>
> def visit_NameNode(self, node):
> print node.dump()
> return node
>
> It is called for every name node in the parse tree.
>
> but this one is not called for every matching node:
>
> def visit_CNameDeclaratorNode(self, node):
> print node.dump()
> return node
>
> Specifically, it is only called when the CNameDeclaratorNode is part
> of (a descendant of) a CArgDeclNode. When it's part of (a descendant
> of) a CVarDefNode it is not called.
Great that you're making progress.
Yes, there is something I'd rather tell you about this :-) The transform
works by recursive descent, and when a node type is intercepted, one
needs to actively visit the children as well.
This is done by self.visitchildren(node); see in visit_FuncDefNode for
an example. Since visitchildren is never called in CVarDefNode, the
children of CVarDefNode are never visited.
Also, the node will be replaced with whatever it returns.
visit_CVarDefNode returns None so that the entire declaration is removed
from the tree, as it is no longer needed (which is why one isn't
analysing the children as well).
(Depending on what you need this for, you could be able to extract the
information from the attributes of the enclosing FuncDefNode; I think
there's a Scope there somewhere which you can inspect the entries of.)
--
Dag Sverre
--
Dag Sverre
More information about the Cython-dev
mailing list