[Python-checkins] python/dist/src/Python ast.c,1.1.2.50,1.1.2.51

jhylton at users.sourceforge.net jhylton at users.sourceforge.net
Fri Apr 23 00:31:25 EDT 2004


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13867

Modified Files:
      Tag: ast-branch
	ast.c 
Log Message:
Complain if non-default arguments follow default arguments.


Index: ast.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/ast.c,v
retrieving revision 1.1.2.50
retrieving revision 1.1.2.51
diff -C2 -d -r1.1.2.50 -r1.1.2.51
*** ast.c	21 Apr 2004 17:45:09 -0000	1.1.2.50
--- ast.c	23 Apr 2004 04:31:22 -0000	1.1.2.51
***************
*** 522,526 ****
              | '**' NAME) | fpdef ['=' test] (',' fpdef ['=' test])* [',']
      */
!     int i, n_args = 0, n_defaults = 0;
      asdl_seq *args, *defaults;
      identifier vararg = NULL, kwarg = NULL;
--- 522,526 ----
              | '**' NAME) | fpdef ['=' test] (',' fpdef ['=' test])* [',']
      */
!     int i, n_args = 0, n_defaults = 0, found_default = 0;
      asdl_seq *args, *defaults;
      identifier vararg = NULL, kwarg = NULL;
***************
*** 537,542 ****
      for (i = 0; i < NCH(n); i++) {
  	ch = CHILD(n, i);
! 	if (TYPE(ch) == fpdef)
  	    n_args++;
  	if (TYPE(ch) == EQUAL)
  	    n_defaults++;
--- 537,543 ----
      for (i = 0; i < NCH(n); i++) {
  	ch = CHILD(n, i);
! 	if (TYPE(ch) == fpdef) {
  	    n_args++;
+ 	}
  	if (TYPE(ch) == EQUAL)
  	    n_defaults++;
***************
*** 557,560 ****
--- 558,576 ----
  	switch (TYPE(ch)) {
              case fpdef:
+                 /* XXX Need to worry about checking if TYPE(CHILD(n, i+1)) is
+                    anything other than EQUAL or a comma? */
+                 /* XXX Should NCH(n) check be made a separate check? */
+                 if (i + 1 < NCH(n) && TYPE(CHILD(n, i + 1)) == EQUAL) {
+                     asdl_seq_APPEND(defaults, 
+ 				    ast_for_expr(c, CHILD(n, i + 2)));
+                     i += 2;
+ 		    found_default = 1;
+                 }
+ 		else if (found_default) {
+ 		    ast_error(n, 
+ 			     "non-default argument follows default argument");
+ 		    goto error;
+ 		}
+ 
                  if (NCH(ch) == 3) {
                      asdl_seq_APPEND(args, 
***************
*** 566,576 ****
                                                 Param));
  		}
-                 /* XXX Need to worry about checking if TYPE(CHILD(n, i+1)) is
-                    anything other than EQUAL or a comma? */
-                 /* XXX Should NCH(n) check be made a separate check? */
-                 if (i + 1 < NCH(n) && TYPE(CHILD(n, i + 1)) == EQUAL) {
-                     asdl_seq_APPEND(defaults, ast_for_expr(c, CHILD(n, i + 2)));
-                     i += 2;
-                 }
                  i += 2; /* the name and the comma */
                  break;
--- 582,585 ----




More information about the Python-checkins mailing list