[Chicago] AST constructure
Daniel Uber
djuber at gmail.com
Mon May 6 13:28:55 CEST 2013
And that was indeed wrong. What actually is happening is that
GeneratorExp is the real function in source code, and the #define just
makes that name a private one in the output. The definition, located in
Python-ast.c, looks like:
expr_ty
GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
PyArena *arena)
{
In any case, I wasn't far off before, what happens is it builds an
object out of the supplied arguments and hands you back an expression
pointer.
Dan Uber
On 5/5/13 9:45 AM, Daniel Uber wrote:
> Having never looked too deeply into this my answer might be wrong, but
> the line right after the define you found is
> expr_ty _Py_GeneratorExp(expr_ty elt, asdl_seq * generators, int
> lineno, int
> col_offset, PyArena *arena);
>
> So it looks like it's just an expr_ty. The relevant parts of the
> generator are
> struct {
> expr_ty elt;
> asdl_seq *generators;
> } GeneratorExp;
> which is buried inside _expr definition.
>
> At the top of the file expr_ty is pointer to struct _expr, which is
> basically a union type of all the possible expressions, plus an
> expr_kind flag to identify the contents.
> In my copy of the header, that definition starts around line 187.
>
> FWIW, I was looking through a 3.3.1 copy of the source tree, but it
> may be similar in 2.x
>
> Daniel Uber
>
>
> On 5/5/13 7:35 AM, shangyu wrote:
>> Hi dear all,
>> I'm reading Python source code and know there is a transition from
>> CST to AST . Python will call some kind of function which convert the
>> CST node to a AST node , for example , in function ast_for_itercomp
>> there is a call to GeneratorExp . The latter is a macro point to
>> _Py_GeneratorExp
>> #define GeneratorExp(a0, a1, a2, a3, a4) _Py_GeneratorExp(a0, a1, a2,
>> a3, a4)
>> I can't go further more because I can't find out the difinition of
>> _Py_GeneratorExp ,
>> so , where is the _Py_GeneratorExp ? Thanks in advance !
>>
>>
>> _______________________________________________
>> Chicago mailing list
>> Chicago at python.org
>> http://mail.python.org/mailman/listinfo/chicago
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20130506/18e1065b/attachment.html>
More information about the Chicago
mailing list