[Python-checkins] python/dist/src/Python ast.c,1.1.2.28,1.1.2.29

bcannon@users.sourceforge.net bcannon@users.sourceforge.net
2003年6月30日 22:32:39 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1:/tmp/cvs-serv14755/Python
Modified Files:
 Tag: ast-branch
	ast.c 
Log Message:
Catch when function arguments are out of order in terms of kinds of arguments
(default args, *NAME, etc.). Needs better error reporting, though.
Currently causes a bus error (at least under OS X) because calls to the
affected function do not currently check the return value for possible NULL
arguments to flag a failure.
Index: ast.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/ast.c,v
retrieving revision 1.1.2.28
retrieving revision 1.1.2.29
diff -C2 -d -r1.1.2.28 -r1.1.2.29
*** ast.c	1 Jul 2003 05:24:58 -0000	1.1.2.28
--- ast.c	1 Jul 2003 05:32:37 -0000	1.1.2.29
***************
*** 92,96 ****
 }
 
! mod_ty PyAST_FromNode(const node *n)
 {
 int i, j, num, total;
--- 92,100 ----
 }
 
! /* Generate AST from concrete syntax tree
! */
! 
! mod_ty
! PyAST_FromNode(const node *n)
 {
 int i, j, num, total;
***************
*** 352,355 ****
--- 356,361 ----
 /* XXX TO DO
 check for invalid argument lists like normal after default
+ DONE; causes bus error since calls to this function do not check
+ for possible NULL result to signal an error.
 handle nested tuple arguments
 */
***************
*** 363,366 ****
--- 369,377 ----
 identifier vararg = NULL, kwarg = NULL;
 node *ch;
+ /* Used to make sure that different kinds of arguments come in the proper
+ order */
+ enum parameter_kinds
+ {fpdef_kind=1, defaults_kind=2, vararg_kind=3, kwarg_kind=4}
+ parameter_kind = fpdef_kind;
 
 if (TYPE(n) == parameters) {
***************
*** 404,412 ****
 		return NULL;
 	 }
! 	 if (TYPE(CHILD(ch, 0)) == NAME)
! 		asdl_seq_APPEND(args, Name(NEW_IDENTIFIER(CHILD(ch, 0)),
! 					 Param));
 	 if (i + 1 < NCH(n) && TYPE(CHILD(n, i + 1)) == EQUAL) {
 		asdl_seq_APPEND(defaults, ast_for_expr(CHILD(n, i + 2)));
 		i += 2;
 	 }
--- 415,437 ----
 		return NULL;
 	 }
! 	 if (TYPE(CHILD(ch, 0)) == NAME) {
! if (parameter_kind > fpdef_kind) {
! fprintf(stderr, "Error in order of arg kinds\n");
! PyErr_Occurred();
! return NULL;
! }
! asdl_seq_APPEND(args, Name(NEW_IDENTIFIER(CHILD(ch, 0)),
! Param));
! /* Don't need to set parameter_kind since that is the
! default */
! }
 	 if (i + 1 < NCH(n) && TYPE(CHILD(n, i + 1)) == EQUAL) {
+ if (parameter_kind > defaults_kind) {
+ fprintf(stderr, "Error in order of arg kinds\n");
+ PyErr_Occurred();
+ return NULL;
+ }
 		asdl_seq_APPEND(defaults, ast_for_expr(CHILD(n, i + 2)));
+ parameter_kind = defaults_kind;
 		i += 2;
 	 }
***************
*** 414,422 ****
--- 439,459 ----
 	 break;
 	case STAR:
+ if (parameter_kind > vararg_kind) {
+ fprintf(stderr, "Error in order of arg kinds\n");
+ PyErr_Occurred();
+ return NULL;
+ }
 	 vararg = NEW_IDENTIFIER(CHILD(n, i+1));
+ parameter_kind = vararg_kind;
 	 i += 3;
 	 break;
 	case DOUBLESTAR:
+ if (parameter_kind > kwarg_kind) {
+ fprintf(stderr, "Error in order of arg kinds\n");
+ PyErr_Occurred();
+ return NULL;
+ }
 	 kwarg = NEW_IDENTIFIER(CHILD(n, i+1));
+ parameter_kind = kwarg_kind;
 	 i += 3;
 	 break;

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