[Python-checkins] python/dist/src/Python symtable.c, 2.10.8.18, 2.10.8.19 ast.c, 1.1.2.43, 1.1.2.44

nnorwitz at projects.sourceforge.net nnorwitz at projects.sourceforge.net
Sat Jan 24 14:46:29 EST 2004


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23106/Python
Modified Files:
 Tag: ast-branch
	symtable.c ast.c 
Log Message:
handle nested tuple arguments
Index: symtable.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/symtable.c,v
retrieving revision 2.10.8.18
retrieving revision 2.10.8.19
diff -C2 -d -r2.10.8.18 -r2.10.8.19
*** symtable.c	24 Jan 2004 18:33:38 -0000	2.10.8.18
--- symtable.c	24 Jan 2004 19:43:46 -0000	2.10.8.19
***************
*** 853,863 ****
 symtable_visit_params(struct symtable *st, asdl_seq *args, int toplevel)
 {
! 	int i;
 	
 	for (i = 0; i < asdl_seq_LEN(args); i++) {
 		expr_ty arg = asdl_seq_GET(args, i);
 		if (arg->kind == Name_kind) {
 			assert(arg->v.Name.ctx == Param ||
! arg->v.Name.ctx == Store);
 			if (!symtable_add_def(st, arg->v.Name.id, DEF_PARAM))
 				return 0;
--- 853,864 ----
 symtable_visit_params(struct symtable *st, asdl_seq *args, int toplevel)
 {
! 	int i, complex = 0;
 	
+ /* go through all the toplevel arguments first */
 	for (i = 0; i < asdl_seq_LEN(args); i++) {
 		expr_ty arg = asdl_seq_GET(args, i);
 		if (arg->kind == Name_kind) {
 			assert(arg->v.Name.ctx == Param ||
! (arg->v.Name.ctx == Store && !toplevel));
 			if (!symtable_add_def(st, arg->v.Name.id, DEF_PARAM))
 				return 0;
***************
*** 865,874 ****
 		else if (arg->kind == Tuple_kind) {
 			assert(arg->v.Tuple.ctx == Store);
 			if (toplevel) {
 				if (!symtable_implicit_arg(st, i))
 					return 0;
 			}
- 			if (!symtable_visit_params(st, arg->v.Tuple.elts, 0))
- 				return 0;
 		}
 		else {
--- 866,874 ----
 		else if (arg->kind == Tuple_kind) {
 			assert(arg->v.Tuple.ctx == Store);
+ complex = 1;
 			if (toplevel) {
 				if (!symtable_implicit_arg(st, i))
 					return 0;
 			}
 		}
 		else {
***************
*** 878,881 ****
--- 878,891 ----
 		}
 	}
+ 
+ /* visit all the nested arguments */
+ if (complex) {
+ for (i = 0; i < asdl_seq_LEN(args); i++) {
+ expr_ty arg = asdl_seq_GET(args, i);
+ if (arg->kind == Tuple_kind &&
+ !symtable_visit_params(st, arg->v.Tuple.elts, 0))
+ return 0;
+ }
+ 	}
 	
 	return 1;
Index: ast.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/ast.c,v
retrieving revision 1.1.2.43
retrieving revision 1.1.2.44
diff -C2 -d -r1.1.2.43 -r1.1.2.44
*** ast.c	23 Jan 2004 16:03:25 -0000	1.1.2.43
--- ast.c	24 Jan 2004 19:44:12 -0000	1.1.2.44
***************
*** 181,185 ****
 }
 case encoding_decl:
! 	 /* XXX need to handle properlyi, ignore for now */
 stmts = asdl_seq_new(1);
 if (!stmts)
--- 181,185 ----
 }
 case encoding_decl:
! 	 /* XXX need to handle properly, ignore for now */
 stmts = asdl_seq_new(1);
 if (!stmts)
***************
*** 428,437 ****
 }
 
 /* Create AST for argument list.
 
 XXX TO DO:
 - check for invalid argument lists like normal after default
- - handle nested tuple arguments
- - handle default arguments properly (might be problem somewhere else)
 */
 
--- 428,456 ----
 }
 
+ static expr_ty
+ compiler_complex_args(const node *n)
+ {
+ int i, len = (NCH(n) + 1) / 2;
+ asdl_seq *args = asdl_seq_new(len);
+ if (!args)
+ return NULL;
+ 
+ for (i = 0; i < len; i++) {
+ const node *child = CHILD(CHILD(n, 2*i), 0);
+ expr_ty arg;
+ if (TYPE(child) == NAME)
+ arg = Name(NEW_IDENTIFIER(child), Store);
+ else
+ arg = compiler_complex_args(child);
+ asdl_seq_SET(args, i, arg);
+ }
+ 
+ return Tuple(args, Store);
+ }
+ 
 /* Create AST for argument list.
 
 XXX TO DO:
 - check for invalid argument lists like normal after default
 */
 
***************
*** 479,485 ****
 case fpdef:
 if (NCH(ch) == 3)
! /* XXX don't handle fplist yet */
! goto error;
! if (TYPE(CHILD(ch, 0)) == NAME)
 /* XXX check return value of Name call */
 asdl_seq_APPEND(args, Name(NEW_IDENTIFIER(CHILD(ch, 0)),
--- 498,504 ----
 case fpdef:
 if (NCH(ch) == 3)
! asdl_seq_APPEND(args, 
! compiler_complex_args(CHILD(ch, 1))); 
! else if (TYPE(CHILD(ch, 0)) == NAME)
 /* XXX check return value of Name call */
 asdl_seq_APPEND(args, Name(NEW_IDENTIFIER(CHILD(ch, 0)),


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /