[Python-checkins] commit of r41581 - in python/branches/ast-objects: Include/Python-ast.h Parser/asdl_c.py Python/Python-ast.c

martin.v.loewis python-checkins at python.org
Sat Dec 3 10:38:55 CET 2005


Author: martin.v.loewis
Date: Sat Dec  3 10:38:50 2005
New Revision: 41581

Modified:
   python/branches/ast-objects/Include/Python-ast.h
   python/branches/ast-objects/Parser/asdl_c.py
   python/branches/ast-objects/Python/Python-ast.c
Log:
Add field accessor macros.
Add create macros for products.
Allow passing NULL for optional and list projections.


Modified: python/branches/ast-objects/Include/Python-ast.h
==============================================================================
--- python/branches/ast-objects/Include/Python-ast.h	(original)
+++ python/branches/ast-objects/Include/Python-ast.h	Sat Dec  3 10:38:50 2005
@@ -11,6 +11,7 @@
         PyObject_HEAD
         enum {Module_kind, Interactive_kind, Expression_kind, Suite_kind} _kind;
 };
+#define mod_kind(o) (((struct _mod*)o)->_kind)
 
 PyAPI_DATA(PyTypeObject) Py_Module_Type;
 #define Module_Check(op) PyObject_TypeCheck(op, &Py_Module_Type)
@@ -21,6 +22,7 @@
 };
 PyObject *Py_Module_New(PyObject*);
 #define Module Py_Module_New
+#define Module_body(o) (((struct _Module*)o)->body)
 
 PyAPI_DATA(PyTypeObject) Py_Interactive_Type;
 #define Interactive_Check(op) PyObject_TypeCheck(op, &Py_Interactive_Type)
@@ -31,6 +33,7 @@
 };
 PyObject *Py_Interactive_New(PyObject*);
 #define Interactive Py_Interactive_New
+#define Interactive_body(o) (((struct _Interactive*)o)->body)
 
 PyAPI_DATA(PyTypeObject) Py_Expression_Type;
 #define Expression_Check(op) PyObject_TypeCheck(op, &Py_Expression_Type)
@@ -41,6 +44,7 @@
 };
 PyObject *Py_Expression_New(PyObject*);
 #define Expression Py_Expression_New
+#define Expression_body(o) (((struct _Expression*)o)->body)
 
 PyAPI_DATA(PyTypeObject) Py_Suite_Type;
 #define Suite_Check(op) PyObject_TypeCheck(op, &Py_Suite_Type)
@@ -51,6 +55,7 @@
 };
 PyObject *Py_Suite_New(PyObject*);
 #define Suite Py_Suite_New
+#define Suite_body(o) (((struct _Suite*)o)->body)
 
 PyAPI_DATA(PyTypeObject) Py_stmt_Type;
 #define stmt_Check(op) PyObject_TypeCheck(op, &Py_stmt_Type)
@@ -65,6 +70,7 @@
                _kind;
         int lineno;
 };
+#define stmt_kind(o) (((struct _stmt*)o)->_kind)
 
 PyAPI_DATA(PyTypeObject) Py_FunctionDef_Type;
 #define FunctionDef_Check(op) PyObject_TypeCheck(op, &Py_FunctionDef_Type)
@@ -78,6 +84,10 @@
 };
 PyObject *Py_FunctionDef_New(PyObject*, PyObject*, PyObject*, PyObject*, int);
 #define FunctionDef Py_FunctionDef_New
+#define FunctionDef_name(o) (((struct _FunctionDef*)o)->name)
+#define FunctionDef_args(o) (((struct _FunctionDef*)o)->args)
+#define FunctionDef_body(o) (((struct _FunctionDef*)o)->body)
+#define FunctionDef_decorators(o) (((struct _FunctionDef*)o)->decorators)
 
 PyAPI_DATA(PyTypeObject) Py_ClassDef_Type;
 #define ClassDef_Check(op) PyObject_TypeCheck(op, &Py_ClassDef_Type)
@@ -90,6 +100,9 @@
 };
 PyObject *Py_ClassDef_New(PyObject*, PyObject*, PyObject*, int);
 #define ClassDef Py_ClassDef_New
+#define ClassDef_name(o) (((struct _ClassDef*)o)->name)
+#define ClassDef_bases(o) (((struct _ClassDef*)o)->bases)
+#define ClassDef_body(o) (((struct _ClassDef*)o)->body)
 
 PyAPI_DATA(PyTypeObject) Py_Return_Type;
 #define Return_Check(op) PyObject_TypeCheck(op, &Py_Return_Type)
@@ -100,6 +113,7 @@
 };
 PyObject *Py_Return_New(PyObject*, int);
 #define Return Py_Return_New
+#define Return_value(o) (((struct _Return*)o)->value)
 
 PyAPI_DATA(PyTypeObject) Py_Delete_Type;
 #define Delete_Check(op) PyObject_TypeCheck(op, &Py_Delete_Type)
@@ -110,6 +124,7 @@
 };
 PyObject *Py_Delete_New(PyObject*, int);
 #define Delete Py_Delete_New
+#define Delete_targets(o) (((struct _Delete*)o)->targets)
 
 PyAPI_DATA(PyTypeObject) Py_Assign_Type;
 #define Assign_Check(op) PyObject_TypeCheck(op, &Py_Assign_Type)
@@ -121,6 +136,8 @@
 };
 PyObject *Py_Assign_New(PyObject*, PyObject*, int);
 #define Assign Py_Assign_New
+#define Assign_targets(o) (((struct _Assign*)o)->targets)
+#define Assign_value(o) (((struct _Assign*)o)->value)
 
 PyAPI_DATA(PyTypeObject) Py_AugAssign_Type;
 #define AugAssign_Check(op) PyObject_TypeCheck(op, &Py_AugAssign_Type)
@@ -133,6 +150,9 @@
 };
 PyObject *Py_AugAssign_New(PyObject*, PyObject*, PyObject*, int);
 #define AugAssign Py_AugAssign_New
+#define AugAssign_target(o) (((struct _AugAssign*)o)->target)
+#define AugAssign_op(o) (((struct _AugAssign*)o)->op)
+#define AugAssign_value(o) (((struct _AugAssign*)o)->value)
 
 PyAPI_DATA(PyTypeObject) Py_Print_Type;
 #define Print_Check(op) PyObject_TypeCheck(op, &Py_Print_Type)
@@ -145,6 +165,9 @@
 };
 PyObject *Py_Print_New(PyObject*, PyObject*, PyObject*, int);
 #define Print Py_Print_New
+#define Print_dest(o) (((struct _Print*)o)->dest)
+#define Print_values(o) (((struct _Print*)o)->values)
+#define Print_nl(o) (((struct _Print*)o)->nl)
 
 PyAPI_DATA(PyTypeObject) Py_For_Type;
 #define For_Check(op) PyObject_TypeCheck(op, &Py_For_Type)
@@ -158,6 +181,10 @@
 };
 PyObject *Py_For_New(PyObject*, PyObject*, PyObject*, PyObject*, int);
 #define For Py_For_New
+#define For_target(o) (((struct _For*)o)->target)
+#define For_iter(o) (((struct _For*)o)->iter)
+#define For_body(o) (((struct _For*)o)->body)
+#define For_orelse(o) (((struct _For*)o)->orelse)
 
 PyAPI_DATA(PyTypeObject) Py_While_Type;
 #define While_Check(op) PyObject_TypeCheck(op, &Py_While_Type)
@@ -170,6 +197,9 @@
 };
 PyObject *Py_While_New(PyObject*, PyObject*, PyObject*, int);
 #define While Py_While_New
+#define While_test(o) (((struct _While*)o)->test)
+#define While_body(o) (((struct _While*)o)->body)
+#define While_orelse(o) (((struct _While*)o)->orelse)
 
 PyAPI_DATA(PyTypeObject) Py_If_Type;
 #define If_Check(op) PyObject_TypeCheck(op, &Py_If_Type)
@@ -182,6 +212,9 @@
 };
 PyObject *Py_If_New(PyObject*, PyObject*, PyObject*, int);
 #define If Py_If_New
+#define If_test(o) (((struct _If*)o)->test)
+#define If_body(o) (((struct _If*)o)->body)
+#define If_orelse(o) (((struct _If*)o)->orelse)
 
 PyAPI_DATA(PyTypeObject) Py_Raise_Type;
 #define Raise_Check(op) PyObject_TypeCheck(op, &Py_Raise_Type)
@@ -194,6 +227,9 @@
 };
 PyObject *Py_Raise_New(PyObject*, PyObject*, PyObject*, int);
 #define Raise Py_Raise_New
+#define Raise_type(o) (((struct _Raise*)o)->type)
+#define Raise_inst(o) (((struct _Raise*)o)->inst)
+#define Raise_tback(o) (((struct _Raise*)o)->tback)
 
 PyAPI_DATA(PyTypeObject) Py_TryExcept_Type;
 #define TryExcept_Check(op) PyObject_TypeCheck(op, &Py_TryExcept_Type)
@@ -206,6 +242,9 @@
 };
 PyObject *Py_TryExcept_New(PyObject*, PyObject*, PyObject*, int);
 #define TryExcept Py_TryExcept_New
+#define TryExcept_body(o) (((struct _TryExcept*)o)->body)
+#define TryExcept_handlers(o) (((struct _TryExcept*)o)->handlers)
+#define TryExcept_orelse(o) (((struct _TryExcept*)o)->orelse)
 
 PyAPI_DATA(PyTypeObject) Py_TryFinally_Type;
 #define TryFinally_Check(op) PyObject_TypeCheck(op, &Py_TryFinally_Type)
@@ -217,6 +256,8 @@
 };
 PyObject *Py_TryFinally_New(PyObject*, PyObject*, int);
 #define TryFinally Py_TryFinally_New
+#define TryFinally_body(o) (((struct _TryFinally*)o)->body)
+#define TryFinally_finalbody(o) (((struct _TryFinally*)o)->finalbody)
 
 PyAPI_DATA(PyTypeObject) Py_Assert_Type;
 #define Assert_Check(op) PyObject_TypeCheck(op, &Py_Assert_Type)
@@ -228,6 +269,8 @@
 };
 PyObject *Py_Assert_New(PyObject*, PyObject*, int);
 #define Assert Py_Assert_New
+#define Assert_test(o) (((struct _Assert*)o)->test)
+#define Assert_msg(o) (((struct _Assert*)o)->msg)
 
 PyAPI_DATA(PyTypeObject) Py_Import_Type;
 #define Import_Check(op) PyObject_TypeCheck(op, &Py_Import_Type)
@@ -238,6 +281,7 @@
 };
 PyObject *Py_Import_New(PyObject*, int);
 #define Import Py_Import_New
+#define Import_names(o) (((struct _Import*)o)->names)
 
 PyAPI_DATA(PyTypeObject) Py_ImportFrom_Type;
 #define ImportFrom_Check(op) PyObject_TypeCheck(op, &Py_ImportFrom_Type)
@@ -249,6 +293,8 @@
 };
 PyObject *Py_ImportFrom_New(PyObject*, PyObject*, int);
 #define ImportFrom Py_ImportFrom_New
+#define ImportFrom_module(o) (((struct _ImportFrom*)o)->module)
+#define ImportFrom_names(o) (((struct _ImportFrom*)o)->names)
 
 PyAPI_DATA(PyTypeObject) Py_Exec_Type;
 #define Exec_Check(op) PyObject_TypeCheck(op, &Py_Exec_Type)
@@ -261,6 +307,9 @@
 };
 PyObject *Py_Exec_New(PyObject*, PyObject*, PyObject*, int);
 #define Exec Py_Exec_New
+#define Exec_body(o) (((struct _Exec*)o)->body)
+#define Exec_globals(o) (((struct _Exec*)o)->globals)
+#define Exec_locals(o) (((struct _Exec*)o)->locals)
 
 PyAPI_DATA(PyTypeObject) Py_Global_Type;
 #define Global_Check(op) PyObject_TypeCheck(op, &Py_Global_Type)
@@ -271,6 +320,7 @@
 };
 PyObject *Py_Global_New(PyObject*, int);
 #define Global Py_Global_New
+#define Global_names(o) (((struct _Global*)o)->names)
 
 PyAPI_DATA(PyTypeObject) Py_Expr_Type;
 #define Expr_Check(op) PyObject_TypeCheck(op, &Py_Expr_Type)
@@ -281,6 +331,7 @@
 };
 PyObject *Py_Expr_New(PyObject*, int);
 #define Expr Py_Expr_New
+#define Expr_value(o) (((struct _Expr*)o)->value)
 
 PyAPI_DATA(PyTypeObject) Py_Pass_Type;
 #define Pass_Check(op) PyObject_TypeCheck(op, &Py_Pass_Type)
@@ -320,6 +371,7 @@
                Subscript_kind, Name_kind, List_kind, Tuple_kind} _kind;
         int lineno;
 };
+#define expr_kind(o) (((struct _expr*)o)->_kind)
 
 PyAPI_DATA(PyTypeObject) Py_BoolOp_Type;
 #define BoolOp_Check(op) PyObject_TypeCheck(op, &Py_BoolOp_Type)
@@ -331,6 +383,8 @@
 };
 PyObject *Py_BoolOp_New(PyObject*, PyObject*, int);
 #define BoolOp Py_BoolOp_New
+#define BoolOp_op(o) (((struct _BoolOp*)o)->op)
+#define BoolOp_values(o) (((struct _BoolOp*)o)->values)
 
 PyAPI_DATA(PyTypeObject) Py_BinOp_Type;
 #define BinOp_Check(op) PyObject_TypeCheck(op, &Py_BinOp_Type)
@@ -343,6 +397,9 @@
 };
 PyObject *Py_BinOp_New(PyObject*, PyObject*, PyObject*, int);
 #define BinOp Py_BinOp_New
+#define BinOp_left(o) (((struct _BinOp*)o)->left)
+#define BinOp_op(o) (((struct _BinOp*)o)->op)
+#define BinOp_right(o) (((struct _BinOp*)o)->right)
 
 PyAPI_DATA(PyTypeObject) Py_UnaryOp_Type;
 #define UnaryOp_Check(op) PyObject_TypeCheck(op, &Py_UnaryOp_Type)
@@ -354,6 +411,8 @@
 };
 PyObject *Py_UnaryOp_New(PyObject*, PyObject*, int);
 #define UnaryOp Py_UnaryOp_New
+#define UnaryOp_op(o) (((struct _UnaryOp*)o)->op)
+#define UnaryOp_operand(o) (((struct _UnaryOp*)o)->operand)
 
 PyAPI_DATA(PyTypeObject) Py_Lambda_Type;
 #define Lambda_Check(op) PyObject_TypeCheck(op, &Py_Lambda_Type)
@@ -365,6 +424,8 @@
 };
 PyObject *Py_Lambda_New(PyObject*, PyObject*, int);
 #define Lambda Py_Lambda_New
+#define Lambda_args(o) (((struct _Lambda*)o)->args)
+#define Lambda_body(o) (((struct _Lambda*)o)->body)
 
 PyAPI_DATA(PyTypeObject) Py_Dict_Type;
 #define Dict_Check(op) PyObject_TypeCheck(op, &Py_Dict_Type)
@@ -376,6 +437,8 @@
 };
 PyObject *Py_Dict_New(PyObject*, PyObject*, int);
 #define Dict Py_Dict_New
+#define Dict_keys(o) (((struct _Dict*)o)->keys)
+#define Dict_values(o) (((struct _Dict*)o)->values)
 
 PyAPI_DATA(PyTypeObject) Py_ListComp_Type;
 #define ListComp_Check(op) PyObject_TypeCheck(op, &Py_ListComp_Type)
@@ -387,6 +450,8 @@
 };
 PyObject *Py_ListComp_New(PyObject*, PyObject*, int);
 #define ListComp Py_ListComp_New
+#define ListComp_elt(o) (((struct _ListComp*)o)->elt)
+#define ListComp_generators(o) (((struct _ListComp*)o)->generators)
 
 PyAPI_DATA(PyTypeObject) Py_GeneratorExp_Type;
 #define GeneratorExp_Check(op) PyObject_TypeCheck(op, &Py_GeneratorExp_Type)
@@ -398,6 +463,8 @@
 };
 PyObject *Py_GeneratorExp_New(PyObject*, PyObject*, int);
 #define GeneratorExp Py_GeneratorExp_New
+#define GeneratorExp_elt(o) (((struct _GeneratorExp*)o)->elt)
+#define GeneratorExp_generators(o) (((struct _GeneratorExp*)o)->generators)
 
 PyAPI_DATA(PyTypeObject) Py_Yield_Type;
 #define Yield_Check(op) PyObject_TypeCheck(op, &Py_Yield_Type)
@@ -408,6 +475,7 @@
 };
 PyObject *Py_Yield_New(PyObject*, int);
 #define Yield Py_Yield_New
+#define Yield_value(o) (((struct _Yield*)o)->value)
 
 PyAPI_DATA(PyTypeObject) Py_Compare_Type;
 #define Compare_Check(op) PyObject_TypeCheck(op, &Py_Compare_Type)
@@ -420,6 +488,9 @@
 };
 PyObject *Py_Compare_New(PyObject*, PyObject*, PyObject*, int);
 #define Compare Py_Compare_New
+#define Compare_left(o) (((struct _Compare*)o)->left)
+#define Compare_ops(o) (((struct _Compare*)o)->ops)
+#define Compare_comparators(o) (((struct _Compare*)o)->comparators)
 
 PyAPI_DATA(PyTypeObject) Py_Call_Type;
 #define Call_Check(op) PyObject_TypeCheck(op, &Py_Call_Type)
@@ -435,6 +506,11 @@
 PyObject *Py_Call_New(PyObject*, PyObject*, PyObject*, PyObject*, PyObject*,
                       int);
 #define Call Py_Call_New
+#define Call_func(o) (((struct _Call*)o)->func)
+#define Call_args(o) (((struct _Call*)o)->args)
+#define Call_keywords(o) (((struct _Call*)o)->keywords)
+#define Call_starargs(o) (((struct _Call*)o)->starargs)
+#define Call_kwargs(o) (((struct _Call*)o)->kwargs)
 
 PyAPI_DATA(PyTypeObject) Py_Repr_Type;
 #define Repr_Check(op) PyObject_TypeCheck(op, &Py_Repr_Type)
@@ -445,6 +521,7 @@
 };
 PyObject *Py_Repr_New(PyObject*, int);
 #define Repr Py_Repr_New
+#define Repr_value(o) (((struct _Repr*)o)->value)
 
 PyAPI_DATA(PyTypeObject) Py_Num_Type;
 #define Num_Check(op) PyObject_TypeCheck(op, &Py_Num_Type)
@@ -455,6 +532,7 @@
 };
 PyObject *Py_Num_New(PyObject*, int);
 #define Num Py_Num_New
+#define Num_n(o) (((struct _Num*)o)->n)
 
 PyAPI_DATA(PyTypeObject) Py_Str_Type;
 #define Str_Check(op) PyObject_TypeCheck(op, &Py_Str_Type)
@@ -465,6 +543,7 @@
 };
 PyObject *Py_Str_New(PyObject*, int);
 #define Str Py_Str_New
+#define Str_s(o) (((struct _Str*)o)->s)
 
 PyAPI_DATA(PyTypeObject) Py_Attribute_Type;
 #define Attribute_Check(op) PyObject_TypeCheck(op, &Py_Attribute_Type)
@@ -477,6 +556,9 @@
 };
 PyObject *Py_Attribute_New(PyObject*, PyObject*, PyObject*, int);
 #define Attribute Py_Attribute_New
+#define Attribute_value(o) (((struct _Attribute*)o)->value)
+#define Attribute_attr(o) (((struct _Attribute*)o)->attr)
+#define Attribute_ctx(o) (((struct _Attribute*)o)->ctx)
 
 PyAPI_DATA(PyTypeObject) Py_Subscript_Type;
 #define Subscript_Check(op) PyObject_TypeCheck(op, &Py_Subscript_Type)
@@ -489,6 +571,9 @@
 };
 PyObject *Py_Subscript_New(PyObject*, PyObject*, PyObject*, int);
 #define Subscript Py_Subscript_New
+#define Subscript_value(o) (((struct _Subscript*)o)->value)
+#define Subscript_slice(o) (((struct _Subscript*)o)->slice)
+#define Subscript_ctx(o) (((struct _Subscript*)o)->ctx)
 
 PyAPI_DATA(PyTypeObject) Py_Name_Type;
 #define Name_Check(op) PyObject_TypeCheck(op, &Py_Name_Type)
@@ -500,6 +585,8 @@
 };
 PyObject *Py_Name_New(PyObject*, PyObject*, int);
 #define Name Py_Name_New
+#define Name_id(o) (((struct _Name*)o)->id)
+#define Name_ctx(o) (((struct _Name*)o)->ctx)
 
 PyAPI_DATA(PyTypeObject) Py_List_Type;
 #define List_Check(op) PyObject_TypeCheck(op, &Py_List_Type)
@@ -511,6 +598,8 @@
 };
 PyObject *Py_List_New(PyObject*, PyObject*, int);
 #define List Py_List_New
+#define List_elts(o) (((struct _List*)o)->elts)
+#define List_ctx(o) (((struct _List*)o)->ctx)
 
 PyAPI_DATA(PyTypeObject) Py_Tuple_Type;
 #define Tuple_Check(op) PyObject_TypeCheck(op, &Py_Tuple_Type)
@@ -522,6 +611,8 @@
 };
 PyObject *Py_Tuple_New(PyObject*, PyObject*, int);
 #define Tuple Py_Tuple_New
+#define Tuple_elts(o) (((struct _Tuple*)o)->elts)
+#define Tuple_ctx(o) (((struct _Tuple*)o)->ctx)
 
 PyAPI_DATA(PyTypeObject) Py_expr_context_Type;
 #define expr_context_Check(op) PyObject_TypeCheck(op, &Py_expr_context_Type)
@@ -531,6 +622,7 @@
         enum {Load_kind, Store_kind, Del_kind, AugLoad_kind, AugStore_kind,
                Param_kind} _kind;
 };
+#define expr_context_kind(o) (((struct _expr_context*)o)->_kind)
 
 PyAPI_DATA(PyTypeObject) Py_Load_Type;
 #define Load_Check(op) PyObject_TypeCheck(op, &Py_Load_Type)
@@ -593,6 +685,7 @@
         PyObject_HEAD
         enum {Ellipsis_kind, Slice_kind, ExtSlice_kind, Index_kind} _kind;
 };
+#define slice_kind(o) (((struct _slice*)o)->_kind)
 
 PyAPI_DATA(PyTypeObject) Py_Ellipsis_Type;
 #define Ellipsis_Check(op) PyObject_TypeCheck(op, &Py_Ellipsis_Type)
@@ -614,6 +707,9 @@
 };
 PyObject *Py_Slice_New(PyObject*, PyObject*, PyObject*);
 #define Slice Py_Slice_New
+#define Slice_lower(o) (((struct _Slice*)o)->lower)
+#define Slice_upper(o) (((struct _Slice*)o)->upper)
+#define Slice_step(o) (((struct _Slice*)o)->step)
 
 PyAPI_DATA(PyTypeObject) Py_ExtSlice_Type;
 #define ExtSlice_Check(op) PyObject_TypeCheck(op, &Py_ExtSlice_Type)
@@ -624,6 +720,7 @@
 };
 PyObject *Py_ExtSlice_New(PyObject*);
 #define ExtSlice Py_ExtSlice_New
+#define ExtSlice_dims(o) (((struct _ExtSlice*)o)->dims)
 
 PyAPI_DATA(PyTypeObject) Py_Index_Type;
 #define Index_Check(op) PyObject_TypeCheck(op, &Py_Index_Type)
@@ -634,6 +731,7 @@
 };
 PyObject *Py_Index_New(PyObject*);
 #define Index Py_Index_New
+#define Index_value(o) (((struct _Index*)o)->value)
 
 PyAPI_DATA(PyTypeObject) Py_boolop_Type;
 #define boolop_Check(op) PyObject_TypeCheck(op, &Py_boolop_Type)
@@ -642,6 +740,7 @@
         PyObject_HEAD
         enum {And_kind, Or_kind} _kind;
 };
+#define boolop_kind(o) (((struct _boolop*)o)->_kind)
 
 PyAPI_DATA(PyTypeObject) Py_And_Type;
 #define And_Check(op) PyObject_TypeCheck(op, &Py_And_Type)
@@ -670,6 +769,7 @@
                LShift_kind, RShift_kind, BitOr_kind, BitXor_kind, BitAnd_kind,
                FloorDiv_kind} _kind;
 };
+#define operator_kind(o) (((struct _operator*)o)->_kind)
 
 PyAPI_DATA(PyTypeObject) Py_Add_Type;
 #define Add_Check(op) PyObject_TypeCheck(op, &Py_Add_Type)
@@ -786,6 +886,7 @@
         PyObject_HEAD
         enum {Invert_kind, Not_kind, UAdd_kind, USub_kind} _kind;
 };
+#define unaryop_kind(o) (((struct _unaryop*)o)->_kind)
 
 PyAPI_DATA(PyTypeObject) Py_Invert_Type;
 #define Invert_Check(op) PyObject_TypeCheck(op, &Py_Invert_Type)
@@ -831,6 +932,7 @@
         enum {Eq_kind, NotEq_kind, Lt_kind, LtE_kind, Gt_kind, GtE_kind,
                Is_kind, IsNot_kind, In_kind, NotIn_kind} _kind;
 };
+#define cmpop_kind(o) (((struct _cmpop*)o)->_kind)
 
 PyAPI_DATA(PyTypeObject) Py_Eq_Type;
 #define Eq_Check(op) PyObject_TypeCheck(op, &Py_Eq_Type)
@@ -932,6 +1034,7 @@
         PyObject* ifs; /* expr */
 };
 PyObject *Py_comprehension_New(PyObject*, PyObject*, PyObject*);
+#define comprehension Py_comprehension_New
 
 PyAPI_DATA(PyTypeObject) Py_excepthandler_Type;
 #define excepthandler_Check(op) PyObject_TypeCheck(op, &Py_excepthandler_Type)
@@ -943,6 +1046,7 @@
         PyObject* body; /* stmt */
 };
 PyObject *Py_excepthandler_New(PyObject*, PyObject*, PyObject*);
+#define excepthandler Py_excepthandler_New
 
 PyAPI_DATA(PyTypeObject) Py_arguments_Type;
 #define arguments_Check(op) PyObject_TypeCheck(op, &Py_arguments_Type)
@@ -955,6 +1059,7 @@
         PyObject* defaults; /* expr */
 };
 PyObject *Py_arguments_New(PyObject*, PyObject*, PyObject*, PyObject*);
+#define arguments Py_arguments_New
 
 PyAPI_DATA(PyTypeObject) Py_keyword_Type;
 #define keyword_Check(op) PyObject_TypeCheck(op, &Py_keyword_Type)
@@ -965,6 +1070,7 @@
         PyObject* value; /* expr */
 };
 PyObject *Py_keyword_New(PyObject*, PyObject*);
+#define keyword Py_keyword_New
 
 PyAPI_DATA(PyTypeObject) Py_alias_Type;
 #define alias_Check(op) PyObject_TypeCheck(op, &Py_alias_Type)
@@ -975,4 +1081,5 @@
         PyObject* asname; /* identifier */
 };
 PyObject *Py_alias_New(PyObject*, PyObject*);
+#define alias Py_alias_New
 

Modified: python/branches/ast-objects/Parser/asdl_c.py
==============================================================================
--- python/branches/ast-objects/Parser/asdl_c.py	(original)
+++ python/branches/ast-objects/Parser/asdl_c.py	Sat Dec  3 10:38:50 2005
@@ -133,6 +133,12 @@
                 depth, reflow=False)
         self.emit("",depth)
 
+
+    def emit_field_access(self, name, fields):
+        for f in fields:
+            self.emit("#define %s_%s(o) (((struct _%s*)o)->%s)" %
+                      (name, f.name, name, f.name), 0)
+
     def visitModule(self, mod):
         for dfn in mod.dfns:
             self.visit(dfn)
@@ -156,6 +162,7 @@
             assert type in asdl.builtin_types, type
             emit("%s %s;" % (type, field.name), depth + 1)
         emit("};")
+        emit("#define %s_kind(o) (((struct _%s*)o)->_kind)" % (name, name))
         emit("")
         for t in sum.types:
             self.visitConstructor(name, t, sum.attributes, depth)
@@ -175,6 +182,7 @@
         self.emit("PyObject *Py_%s_New(%s);" % (cons.name, args), depth)
         # for convenience
         self.emit("#define %s Py_%s_New" % (cons.name, cons.name), depth)
+        self.emit_field_access(cons.name, cons.fields)
         self.emit("", depth)
 
     def visitField(self, field, depth):
@@ -191,6 +199,7 @@
             self.visit(f, depth + 1)
         self.emit("};", depth)
         self.emit("PyObject *Py_%s_New(%s);" % (name, ", ".join(field_types)), depth)
+        self.emit("#define %s Py_%s_New" % (name, name), depth)
         self.emit("", depth)
 
 class ForwardVisitor(TraversalVisitor):
@@ -224,8 +233,10 @@
     def emit_ctor(self, name, args, attrs):
         def emit(s, depth=0, reflow=1):
             self.emit(s, depth, reflow)
-        argstr = ", ".join(["%s %s" % (atype, aname)
-                            for atype, aname, opt in args + attrs])
+        argstr = ["%s %s" % (f.type, f.name) for f in args]
+        argstr += ["%s %s" % (argtype, argname)
+                   for argtype, argname, opt in attrs]
+        argstr = ", ".join(argstr)
         
         emit("PyObject*")
         emit("Py_%s_New(%s)" % (name, argstr))
@@ -233,10 +244,19 @@
         emit("struct _%s *result = PyObject_New(struct _%s, &Py_%s_Type);" % (name, name, name), 1, 0)
         emit("if (result == NULL)", 1)
         emit("return NULL;", 2)
-        for argtype, argname, opt in args:
+        for f in args:
+            argtype = get_c_type(f.type)
             if argtype == "PyObject*":
-                emit("Py_INCREF(%s);" % argname, 1)
-            emit("result->%s = %s;" % (argname, argname), 1)
+                if f.opt:
+                    emit("if (%s == NULL) {" % f.name, 1)
+                    emit("Py_INCREF(Py_None);", 2)
+                    emit("%s = Py_None;" % f.name, 2)
+                    emit("}", 1)
+                elif f.seq:
+                    emit("if (%s == NULL)" % f.name, 1)
+                    emit("%s = Py_List_New(0);" % f.name, 2)
+                emit("Py_INCREF(%s);" % f.name, 1)
+            emit("result->%s = %s;" % (f.name, f.name), 1)
         for argtype, argname, opt in attrs:
             if argtype == "PyObject*":
                 emit("Py_INCREF(%s);" % argname, 1)
@@ -411,7 +431,7 @@
         
     def visitProduct(self, prod, name):
         args = self.get_args(prod.fields)
-        self.emit_ctor(str(name), args, [])
+        self.emit_ctor(str(name), prod.fields, [])
         self.emit_dealloc(str(name), args, [])
         self.emit_type(str(name))
         self.emit_validate(str(name), prod.fields, [])
@@ -419,7 +439,7 @@
     def visitConstructor(self, cons, name, attrs):
         args = self.get_args(cons.fields)
         attrs = self.get_args(attrs)
-        self.emit_ctor(cons.name, args, attrs)
+        self.emit_ctor(cons.name, cons.fields, attrs)
         self.emit_dealloc(cons.name, args, attrs)
         self.emit_type(cons.name)
         self.emit_validate(cons.name, cons.fields, attrs)

Modified: python/branches/ast-objects/Python/Python-ast.c
==============================================================================
--- python/branches/ast-objects/Python/Python-ast.c	(original)
+++ python/branches/ast-objects/Python/Python-ast.c	Sat Dec  3 10:38:50 2005
@@ -174,11 +174,13 @@
         return -1;
 }
 PyObject*
-Py_Module_New(PyObject* body)
+Py_Module_New(stmt body)
 {
         struct _Module *result = PyObject_New(struct _Module, &Py_Module_Type);
         if (result == NULL)
                 return NULL;
+        if (body == NULL)
+                body = Py_List_New(0);
         Py_INCREF(body);
         result->body = body;
         return (PyObject*)result;
@@ -257,11 +259,13 @@
 }
 
 PyObject*
-Py_Interactive_New(PyObject* body)
+Py_Interactive_New(stmt body)
 {
         struct _Interactive *result = PyObject_New(struct _Interactive, &Py_Interactive_Type);
         if (result == NULL)
                 return NULL;
+        if (body == NULL)
+                body = Py_List_New(0);
         Py_INCREF(body);
         result->body = body;
         return (PyObject*)result;
@@ -340,7 +344,7 @@
 }
 
 PyObject*
-Py_Expression_New(PyObject* body)
+Py_Expression_New(expr body)
 {
         struct _Expression *result = PyObject_New(struct _Expression, &Py_Expression_Type);
         if (result == NULL)
@@ -414,11 +418,13 @@
 }
 
 PyObject*
-Py_Suite_New(PyObject* body)
+Py_Suite_New(stmt body)
 {
         struct _Suite *result = PyObject_New(struct _Suite, &Py_Suite_Type);
         if (result == NULL)
                 return NULL;
+        if (body == NULL)
+                body = Py_List_New(0);
         Py_INCREF(body);
         result->body = body;
         return (PyObject*)result;
@@ -596,8 +602,8 @@
         return -1;
 }
 PyObject*
-Py_FunctionDef_New(PyObject* name, PyObject* args, PyObject* body, PyObject*
-                   decorators, int lineno)
+Py_FunctionDef_New(identifier name, arguments args, stmt body, expr decorators,
+                   int lineno)
 {
         struct _FunctionDef *result = PyObject_New(struct _FunctionDef, &Py_FunctionDef_Type);
         if (result == NULL)
@@ -606,8 +612,12 @@
         result->name = name;
         Py_INCREF(args);
         result->args = args;
+        if (body == NULL)
+                body = Py_List_New(0);
         Py_INCREF(body);
         result->body = body;
+        if (decorators == NULL)
+                decorators = Py_List_New(0);
         Py_INCREF(decorators);
         result->decorators = decorators;
         result->_base.lineno = lineno;
@@ -711,15 +721,19 @@
 }
 
 PyObject*
-Py_ClassDef_New(PyObject* name, PyObject* bases, PyObject* body, int lineno)
+Py_ClassDef_New(identifier name, expr bases, stmt body, int lineno)
 {
         struct _ClassDef *result = PyObject_New(struct _ClassDef, &Py_ClassDef_Type);
         if (result == NULL)
                 return NULL;
         Py_INCREF(name);
         result->name = name;
+        if (bases == NULL)
+                bases = Py_List_New(0);
         Py_INCREF(bases);
         result->bases = bases;
+        if (body == NULL)
+                body = Py_List_New(0);
         Py_INCREF(body);
         result->body = body;
         result->_base.lineno = lineno;
@@ -818,11 +832,15 @@
 }
 
 PyObject*
-Py_Return_New(PyObject* value, int lineno)
+Py_Return_New(expr value, int lineno)
 {
         struct _Return *result = PyObject_New(struct _Return, &Py_Return_Type);
         if (result == NULL)
                 return NULL;
+        if (value == NULL) {
+                Py_INCREF(Py_None);
+                value = Py_None;
+        }
         Py_INCREF(value);
         result->value = value;
         result->_base.lineno = lineno;
@@ -896,11 +914,13 @@
 }
 
 PyObject*
-Py_Delete_New(PyObject* targets, int lineno)
+Py_Delete_New(expr targets, int lineno)
 {
         struct _Delete *result = PyObject_New(struct _Delete, &Py_Delete_Type);
         if (result == NULL)
                 return NULL;
+        if (targets == NULL)
+                targets = Py_List_New(0);
         Py_INCREF(targets);
         result->targets = targets;
         result->_base.lineno = lineno;
@@ -981,11 +1001,13 @@
 }
 
 PyObject*
-Py_Assign_New(PyObject* targets, PyObject* value, int lineno)
+Py_Assign_New(expr targets, expr value, int lineno)
 {
         struct _Assign *result = PyObject_New(struct _Assign, &Py_Assign_Type);
         if (result == NULL)
                 return NULL;
+        if (targets == NULL)
+                targets = Py_List_New(0);
         Py_INCREF(targets);
         result->targets = targets;
         Py_INCREF(value);
@@ -1073,7 +1095,7 @@
 }
 
 PyObject*
-Py_AugAssign_New(PyObject* target, PyObject* op, PyObject* value, int lineno)
+Py_AugAssign_New(expr target, operator op, expr value, int lineno)
 {
         struct _AugAssign *result = PyObject_New(struct _AugAssign, &Py_AugAssign_Type);
         if (result == NULL)
@@ -1162,13 +1184,19 @@
 }
 
 PyObject*
-Py_Print_New(PyObject* dest, PyObject* values, PyObject* nl, int lineno)
+Py_Print_New(expr dest, expr values, bool nl, int lineno)
 {
         struct _Print *result = PyObject_New(struct _Print, &Py_Print_Type);
         if (result == NULL)
                 return NULL;
+        if (dest == NULL) {
+                Py_INCREF(Py_None);
+                dest = Py_None;
+        }
         Py_INCREF(dest);
         result->dest = dest;
+        if (values == NULL)
+                values = Py_List_New(0);
         Py_INCREF(values);
         result->values = values;
         Py_INCREF(nl);
@@ -1264,8 +1292,7 @@
 }
 
 PyObject*
-Py_For_New(PyObject* target, PyObject* iter, PyObject* body, PyObject* orelse,
-           int lineno)
+Py_For_New(expr target, expr iter, stmt body, stmt orelse, int lineno)
 {
         struct _For *result = PyObject_New(struct _For, &Py_For_Type);
         if (result == NULL)
@@ -1274,8 +1301,12 @@
         result->target = target;
         Py_INCREF(iter);
         result->iter = iter;
+        if (body == NULL)
+                body = Py_List_New(0);
         Py_INCREF(body);
         result->body = body;
+        if (orelse == NULL)
+                orelse = Py_List_New(0);
         Py_INCREF(orelse);
         result->orelse = orelse;
         result->_base.lineno = lineno;
@@ -1379,15 +1410,19 @@
 }
 
 PyObject*
-Py_While_New(PyObject* test, PyObject* body, PyObject* orelse, int lineno)
+Py_While_New(expr test, stmt body, stmt orelse, int lineno)
 {
         struct _While *result = PyObject_New(struct _While, &Py_While_Type);
         if (result == NULL)
                 return NULL;
         Py_INCREF(test);
         result->test = test;
+        if (body == NULL)
+                body = Py_List_New(0);
         Py_INCREF(body);
         result->body = body;
+        if (orelse == NULL)
+                orelse = Py_List_New(0);
         Py_INCREF(orelse);
         result->orelse = orelse;
         result->_base.lineno = lineno;
@@ -1486,15 +1521,19 @@
 }
 
 PyObject*
-Py_If_New(PyObject* test, PyObject* body, PyObject* orelse, int lineno)
+Py_If_New(expr test, stmt body, stmt orelse, int lineno)
 {
         struct _If *result = PyObject_New(struct _If, &Py_If_Type);
         if (result == NULL)
                 return NULL;
         Py_INCREF(test);
         result->test = test;
+        if (body == NULL)
+                body = Py_List_New(0);
         Py_INCREF(body);
         result->body = body;
+        if (orelse == NULL)
+                orelse = Py_List_New(0);
         Py_INCREF(orelse);
         result->orelse = orelse;
         result->_base.lineno = lineno;
@@ -1593,15 +1632,27 @@
 }
 
 PyObject*
-Py_Raise_New(PyObject* type, PyObject* inst, PyObject* tback, int lineno)
+Py_Raise_New(expr type, expr inst, expr tback, int lineno)
 {
         struct _Raise *result = PyObject_New(struct _Raise, &Py_Raise_Type);
         if (result == NULL)
                 return NULL;
+        if (type == NULL) {
+                Py_INCREF(Py_None);
+                type = Py_None;
+        }
         Py_INCREF(type);
         result->type = type;
+        if (inst == NULL) {
+                Py_INCREF(Py_None);
+                inst = Py_None;
+        }
         Py_INCREF(inst);
         result->inst = inst;
+        if (tback == NULL) {
+                Py_INCREF(Py_None);
+                tback = Py_None;
+        }
         Py_INCREF(tback);
         result->tback = tback;
         result->_base.lineno = lineno;
@@ -1691,16 +1742,21 @@
 }
 
 PyObject*
-Py_TryExcept_New(PyObject* body, PyObject* handlers, PyObject* orelse, int
-                 lineno)
+Py_TryExcept_New(stmt body, excepthandler handlers, stmt orelse, int lineno)
 {
         struct _TryExcept *result = PyObject_New(struct _TryExcept, &Py_TryExcept_Type);
         if (result == NULL)
                 return NULL;
+        if (body == NULL)
+                body = Py_List_New(0);
         Py_INCREF(body);
         result->body = body;
+        if (handlers == NULL)
+                handlers = Py_List_New(0);
         Py_INCREF(handlers);
         result->handlers = handlers;
+        if (orelse == NULL)
+                orelse = Py_List_New(0);
         Py_INCREF(orelse);
         result->orelse = orelse;
         result->_base.lineno = lineno;
@@ -1809,13 +1865,17 @@
 }
 
 PyObject*
-Py_TryFinally_New(PyObject* body, PyObject* finalbody, int lineno)
+Py_TryFinally_New(stmt body, stmt finalbody, int lineno)
 {
         struct _TryFinally *result = PyObject_New(struct _TryFinally, &Py_TryFinally_Type);
         if (result == NULL)
                 return NULL;
+        if (body == NULL)
+                body = Py_List_New(0);
         Py_INCREF(body);
         result->body = body;
+        if (finalbody == NULL)
+                finalbody = Py_List_New(0);
         Py_INCREF(finalbody);
         result->finalbody = finalbody;
         result->_base.lineno = lineno;
@@ -1909,13 +1969,17 @@
 }
 
 PyObject*
-Py_Assert_New(PyObject* test, PyObject* msg, int lineno)
+Py_Assert_New(expr test, expr msg, int lineno)
 {
         struct _Assert *result = PyObject_New(struct _Assert, &Py_Assert_Type);
         if (result == NULL)
                 return NULL;
         Py_INCREF(test);
         result->test = test;
+        if (msg == NULL) {
+                Py_INCREF(Py_None);
+                msg = Py_None;
+        }
         Py_INCREF(msg);
         result->msg = msg;
         result->_base.lineno = lineno;
@@ -1994,11 +2058,13 @@
 }
 
 PyObject*
-Py_Import_New(PyObject* names, int lineno)
+Py_Import_New(alias names, int lineno)
 {
         struct _Import *result = PyObject_New(struct _Import, &Py_Import_Type);
         if (result == NULL)
                 return NULL;
+        if (names == NULL)
+                names = Py_List_New(0);
         Py_INCREF(names);
         result->names = names;
         result->_base.lineno = lineno;
@@ -2079,13 +2145,15 @@
 }
 
 PyObject*
-Py_ImportFrom_New(PyObject* module, PyObject* names, int lineno)
+Py_ImportFrom_New(identifier module, alias names, int lineno)
 {
         struct _ImportFrom *result = PyObject_New(struct _ImportFrom, &Py_ImportFrom_Type);
         if (result == NULL)
                 return NULL;
         Py_INCREF(module);
         result->module = module;
+        if (names == NULL)
+                names = Py_List_New(0);
         Py_INCREF(names);
         result->names = names;
         result->_base.lineno = lineno;
@@ -2171,15 +2239,23 @@
 }
 
 PyObject*
-Py_Exec_New(PyObject* body, PyObject* globals, PyObject* locals, int lineno)
+Py_Exec_New(expr body, expr globals, expr locals, int lineno)
 {
         struct _Exec *result = PyObject_New(struct _Exec, &Py_Exec_Type);
         if (result == NULL)
                 return NULL;
         Py_INCREF(body);
         result->body = body;
+        if (globals == NULL) {
+                Py_INCREF(Py_None);
+                globals = Py_None;
+        }
         Py_INCREF(globals);
         result->globals = globals;
+        if (locals == NULL) {
+                Py_INCREF(Py_None);
+                locals = Py_None;
+        }
         Py_INCREF(locals);
         result->locals = locals;
         result->_base.lineno = lineno;
@@ -2266,11 +2342,13 @@
 }
 
 PyObject*
-Py_Global_New(PyObject* names, int lineno)
+Py_Global_New(identifier names, int lineno)
 {
         struct _Global *result = PyObject_New(struct _Global, &Py_Global_Type);
         if (result == NULL)
                 return NULL;
+        if (names == NULL)
+                names = Py_List_New(0);
         Py_INCREF(names);
         result->names = names;
         result->_base.lineno = lineno;
@@ -2349,7 +2427,7 @@
 }
 
 PyObject*
-Py_Expr_New(PyObject* value, int lineno)
+Py_Expr_New(expr value, int lineno)
 {
         struct _Expr *result = PyObject_New(struct _Expr, &Py_Expr_Type);
         if (result == NULL)
@@ -2716,13 +2794,15 @@
         return -1;
 }
 PyObject*
-Py_BoolOp_New(PyObject* op, PyObject* values, int lineno)
+Py_BoolOp_New(boolop op, expr values, int lineno)
 {
         struct _BoolOp *result = PyObject_New(struct _BoolOp, &Py_BoolOp_Type);
         if (result == NULL)
                 return NULL;
         Py_INCREF(op);
         result->op = op;
+        if (values == NULL)
+                values = Py_List_New(0);
         Py_INCREF(values);
         result->values = values;
         result->_base.lineno = lineno;
@@ -2808,7 +2888,7 @@
 }
 
 PyObject*
-Py_BinOp_New(PyObject* left, PyObject* op, PyObject* right, int lineno)
+Py_BinOp_New(expr left, operator op, expr right, int lineno)
 {
         struct _BinOp *result = PyObject_New(struct _BinOp, &Py_BinOp_Type);
         if (result == NULL)
@@ -2897,7 +2977,7 @@
 }
 
 PyObject*
-Py_UnaryOp_New(PyObject* op, PyObject* operand, int lineno)
+Py_UnaryOp_New(unaryop op, expr operand, int lineno)
 {
         struct _UnaryOp *result = PyObject_New(struct _UnaryOp, &Py_UnaryOp_Type);
         if (result == NULL)
@@ -2979,7 +3059,7 @@
 }
 
 PyObject*
-Py_Lambda_New(PyObject* args, PyObject* body, int lineno)
+Py_Lambda_New(arguments args, expr body, int lineno)
 {
         struct _Lambda *result = PyObject_New(struct _Lambda, &Py_Lambda_Type);
         if (result == NULL)
@@ -3061,13 +3141,17 @@
 }
 
 PyObject*
-Py_Dict_New(PyObject* keys, PyObject* values, int lineno)
+Py_Dict_New(expr keys, expr values, int lineno)
 {
         struct _Dict *result = PyObject_New(struct _Dict, &Py_Dict_Type);
         if (result == NULL)
                 return NULL;
+        if (keys == NULL)
+                keys = Py_List_New(0);
         Py_INCREF(keys);
         result->keys = keys;
+        if (values == NULL)
+                values = Py_List_New(0);
         Py_INCREF(values);
         result->values = values;
         result->_base.lineno = lineno;
@@ -3161,13 +3245,15 @@
 }
 
 PyObject*
-Py_ListComp_New(PyObject* elt, PyObject* generators, int lineno)
+Py_ListComp_New(expr elt, comprehension generators, int lineno)
 {
         struct _ListComp *result = PyObject_New(struct _ListComp, &Py_ListComp_Type);
         if (result == NULL)
                 return NULL;
         Py_INCREF(elt);
         result->elt = elt;
+        if (generators == NULL)
+                generators = Py_List_New(0);
         Py_INCREF(generators);
         result->generators = generators;
         result->_base.lineno = lineno;
@@ -3254,13 +3340,15 @@
 }
 
 PyObject*
-Py_GeneratorExp_New(PyObject* elt, PyObject* generators, int lineno)
+Py_GeneratorExp_New(expr elt, comprehension generators, int lineno)
 {
         struct _GeneratorExp *result = PyObject_New(struct _GeneratorExp, &Py_GeneratorExp_Type);
         if (result == NULL)
                 return NULL;
         Py_INCREF(elt);
         result->elt = elt;
+        if (generators == NULL)
+                generators = Py_List_New(0);
         Py_INCREF(generators);
         result->generators = generators;
         result->_base.lineno = lineno;
@@ -3347,11 +3435,15 @@
 }
 
 PyObject*
-Py_Yield_New(PyObject* value, int lineno)
+Py_Yield_New(expr value, int lineno)
 {
         struct _Yield *result = PyObject_New(struct _Yield, &Py_Yield_Type);
         if (result == NULL)
                 return NULL;
+        if (value == NULL) {
+                Py_INCREF(Py_None);
+                value = Py_None;
+        }
         Py_INCREF(value);
         result->value = value;
         result->_base.lineno = lineno;
@@ -3425,15 +3517,19 @@
 }
 
 PyObject*
-Py_Compare_New(PyObject* left, PyObject* ops, PyObject* comparators, int lineno)
+Py_Compare_New(expr left, cmpop ops, expr comparators, int lineno)
 {
         struct _Compare *result = PyObject_New(struct _Compare, &Py_Compare_Type);
         if (result == NULL)
                 return NULL;
         Py_INCREF(left);
         result->left = left;
+        if (ops == NULL)
+                ops = Py_List_New(0);
         Py_INCREF(ops);
         result->ops = ops;
+        if (comparators == NULL)
+                comparators = Py_List_New(0);
         Py_INCREF(comparators);
         result->comparators = comparators;
         result->_base.lineno = lineno;
@@ -3532,20 +3628,32 @@
 }
 
 PyObject*
-Py_Call_New(PyObject* func, PyObject* args, PyObject* keywords, PyObject*
-            starargs, PyObject* kwargs, int lineno)
+Py_Call_New(expr func, expr args, keyword keywords, expr starargs, expr kwargs,
+            int lineno)
 {
         struct _Call *result = PyObject_New(struct _Call, &Py_Call_Type);
         if (result == NULL)
                 return NULL;
         Py_INCREF(func);
         result->func = func;
+        if (args == NULL)
+                args = Py_List_New(0);
         Py_INCREF(args);
         result->args = args;
+        if (keywords == NULL)
+                keywords = Py_List_New(0);
         Py_INCREF(keywords);
         result->keywords = keywords;
+        if (starargs == NULL) {
+                Py_INCREF(Py_None);
+                starargs = Py_None;
+        }
         Py_INCREF(starargs);
         result->starargs = starargs;
+        if (kwargs == NULL) {
+                Py_INCREF(Py_None);
+                kwargs = Py_None;
+        }
         Py_INCREF(kwargs);
         result->kwargs = kwargs;
         result->_base.lineno = lineno;
@@ -3660,7 +3768,7 @@
 }
 
 PyObject*
-Py_Repr_New(PyObject* value, int lineno)
+Py_Repr_New(expr value, int lineno)
 {
         struct _Repr *result = PyObject_New(struct _Repr, &Py_Repr_Type);
         if (result == NULL)
@@ -3735,7 +3843,7 @@
 }
 
 PyObject*
-Py_Num_New(PyObject* n, int lineno)
+Py_Num_New(object n, int lineno)
 {
         struct _Num *result = PyObject_New(struct _Num, &Py_Num_Type);
         if (result == NULL)
@@ -3810,7 +3918,7 @@
 }
 
 PyObject*
-Py_Str_New(PyObject* s, int lineno)
+Py_Str_New(string s, int lineno)
 {
         struct _Str *result = PyObject_New(struct _Str, &Py_Str_Type);
         if (result == NULL)
@@ -3885,7 +3993,7 @@
 }
 
 PyObject*
-Py_Attribute_New(PyObject* value, PyObject* attr, PyObject* ctx, int lineno)
+Py_Attribute_New(expr value, identifier attr, expr_context ctx, int lineno)
 {
         struct _Attribute *result = PyObject_New(struct _Attribute, &Py_Attribute_Type);
         if (result == NULL)
@@ -3974,7 +4082,7 @@
 }
 
 PyObject*
-Py_Subscript_New(PyObject* value, PyObject* slice, PyObject* ctx, int lineno)
+Py_Subscript_New(expr value, slice slice, expr_context ctx, int lineno)
 {
         struct _Subscript *result = PyObject_New(struct _Subscript, &Py_Subscript_Type);
         if (result == NULL)
@@ -4063,7 +4171,7 @@
 }
 
 PyObject*
-Py_Name_New(PyObject* id, PyObject* ctx, int lineno)
+Py_Name_New(identifier id, expr_context ctx, int lineno)
 {
         struct _Name *result = PyObject_New(struct _Name, &Py_Name_Type);
         if (result == NULL)
@@ -4145,11 +4253,13 @@
 }
 
 PyObject*
-Py_List_New(PyObject* elts, PyObject* ctx, int lineno)
+Py_List_New(expr elts, expr_context ctx, int lineno)
 {
         struct _List *result = PyObject_New(struct _List, &Py_List_Type);
         if (result == NULL)
                 return NULL;
+        if (elts == NULL)
+                elts = Py_List_New(0);
         Py_INCREF(elts);
         result->elts = elts;
         Py_INCREF(ctx);
@@ -4236,11 +4346,13 @@
 }
 
 PyObject*
-Py_Tuple_New(PyObject* elts, PyObject* ctx, int lineno)
+Py_Tuple_New(expr elts, expr_context ctx, int lineno)
 {
         struct _Tuple *result = PyObject_New(struct _Tuple, &Py_Tuple_Type);
         if (result == NULL)
                 return NULL;
+        if (elts == NULL)
+                elts = Py_List_New(0);
         Py_INCREF(elts);
         result->elts = elts;
         Py_INCREF(ctx);
@@ -4919,15 +5031,27 @@
 }
 
 PyObject*
-Py_Slice_New(PyObject* lower, PyObject* upper, PyObject* step)
+Py_Slice_New(expr lower, expr upper, expr step)
 {
         struct _Slice *result = PyObject_New(struct _Slice, &Py_Slice_Type);
         if (result == NULL)
                 return NULL;
+        if (lower == NULL) {
+                Py_INCREF(Py_None);
+                lower = Py_None;
+        }
         Py_INCREF(lower);
         result->lower = lower;
+        if (upper == NULL) {
+                Py_INCREF(Py_None);
+                upper = Py_None;
+        }
         Py_INCREF(upper);
         result->upper = upper;
+        if (step == NULL) {
+                Py_INCREF(Py_None);
+                step = Py_None;
+        }
         Py_INCREF(step);
         result->step = step;
         return (PyObject*)result;
@@ -5016,11 +5140,13 @@
 }
 
 PyObject*
-Py_ExtSlice_New(PyObject* dims)
+Py_ExtSlice_New(slice dims)
 {
         struct _ExtSlice *result = PyObject_New(struct _ExtSlice, &Py_ExtSlice_Type);
         if (result == NULL)
                 return NULL;
+        if (dims == NULL)
+                dims = Py_List_New(0);
         Py_INCREF(dims);
         result->dims = dims;
         return (PyObject*)result;
@@ -5100,7 +5226,7 @@
 }
 
 PyObject*
-Py_Index_New(PyObject* value)
+Py_Index_New(expr value)
 {
         struct _Index *result = PyObject_New(struct _Index, &Py_Index_Type);
         if (result == NULL)
@@ -7298,7 +7424,7 @@
 }
 
 PyObject*
-Py_comprehension_New(PyObject* target, PyObject* iter, PyObject* ifs)
+Py_comprehension_New(expr target, expr iter, expr ifs)
 {
         struct _comprehension *result = PyObject_New(struct _comprehension, &Py_comprehension_Type);
         if (result == NULL)
@@ -7307,6 +7433,8 @@
         result->target = target;
         Py_INCREF(iter);
         result->iter = iter;
+        if (ifs == NULL)
+                ifs = Py_List_New(0);
         Py_INCREF(ifs);
         result->ifs = ifs;
         return (PyObject*)result;
@@ -7395,15 +7523,25 @@
 }
 
 PyObject*
-Py_excepthandler_New(PyObject* type, PyObject* name, PyObject* body)
+Py_excepthandler_New(expr type, expr name, stmt body)
 {
         struct _excepthandler *result = PyObject_New(struct _excepthandler, &Py_excepthandler_Type);
         if (result == NULL)
                 return NULL;
+        if (type == NULL) {
+                Py_INCREF(Py_None);
+                type = Py_None;
+        }
         Py_INCREF(type);
         result->type = type;
+        if (name == NULL) {
+                Py_INCREF(Py_None);
+                name = Py_None;
+        }
         Py_INCREF(name);
         result->name = name;
+        if (body == NULL)
+                body = Py_List_New(0);
         Py_INCREF(body);
         result->body = body;
         return (PyObject*)result;
@@ -7498,18 +7636,29 @@
 }
 
 PyObject*
-Py_arguments_New(PyObject* args, PyObject* vararg, PyObject* kwarg, PyObject*
-                 defaults)
+Py_arguments_New(expr args, identifier vararg, identifier kwarg, expr defaults)
 {
         struct _arguments *result = PyObject_New(struct _arguments, &Py_arguments_Type);
         if (result == NULL)
                 return NULL;
+        if (args == NULL)
+                args = Py_List_New(0);
         Py_INCREF(args);
         result->args = args;
+        if (vararg == NULL) {
+                Py_INCREF(Py_None);
+                vararg = Py_None;
+        }
         Py_INCREF(vararg);
         result->vararg = vararg;
+        if (kwarg == NULL) {
+                Py_INCREF(Py_None);
+                kwarg = Py_None;
+        }
         Py_INCREF(kwarg);
         result->kwarg = kwarg;
+        if (defaults == NULL)
+                defaults = Py_List_New(0);
         Py_INCREF(defaults);
         result->defaults = defaults;
         return (PyObject*)result;
@@ -7614,7 +7763,7 @@
 }
 
 PyObject*
-Py_keyword_New(PyObject* arg, PyObject* value)
+Py_keyword_New(identifier arg, expr value)
 {
         struct _keyword *result = PyObject_New(struct _keyword, &Py_keyword_Type);
         if (result == NULL)
@@ -7695,13 +7844,17 @@
 }
 
 PyObject*
-Py_alias_New(PyObject* name, PyObject* asname)
+Py_alias_New(identifier name, identifier asname)
 {
         struct _alias *result = PyObject_New(struct _alias, &Py_alias_Type);
         if (result == NULL)
                 return NULL;
         Py_INCREF(name);
         result->name = name;
+        if (asname == NULL) {
+                Py_INCREF(Py_None);
+                asname = Py_None;
+        }
         Py_INCREF(asname);
         result->asname = asname;
         return (PyObject*)result;


More information about the Python-checkins mailing list