[Python-checkins] python/dist/src/Python ast.c,1.1.2.6,1.1.2.7

jhylton@users.sourceforge.net jhylton@users.sourceforge.net
Mon, 30 Sep 2002 11:21:47 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv24574

Modified Files:
      Tag: ast-branch
	ast.c 
Log Message:
Several small improvements.

Add handle for BinOp(_, Pow, _).
Use asdl_seq_SET() in ast_for_suite() instead of APPEND().
Repair conversion to Repr().  The body is a testlist1, not an expr.


Index: ast.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/ast.c,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -C2 -d -r1.1.2.6 -r1.1.2.7
*** ast.c	27 Sep 2002 23:10:43 -0000	1.1.2.6
--- ast.c	30 Sep 2002 18:21:45 -0000	1.1.2.7
***************
*** 142,147 ****
  	    if (!stmts)
  		return NULL;
! 	    if (num == 1)
  		asdl_seq_SET(stmts, 0, ast_for_stmt(n));
  	    else {
  		/* Only a simple_stmt can contain multiple statements. */
--- 142,148 ----
  	    if (!stmts)
  		return NULL;
! 	    if (num == 1) {
  		asdl_seq_SET(stmts, 0, ast_for_stmt(n));
+ 	    }
  	    else {
  		/* Only a simple_stmt can contain multiple statements. */
***************
*** 593,597 ****
      }
      case BACKQUOTE: /* repr */
! 	return Repr(ast_for_expr(CHILD(n, 1)));
  	break;
      default:
--- 594,598 ----
      }
      case BACKQUOTE: /* repr */
! 	return Repr(ast_for_testlist(CHILD(n, 1)));
  	break;
      default:
***************
*** 748,753 ****
  	}
  	break;
!     case power: 
!     {
  	expr_ty e = ast_for_atom(CHILD(n, 0));
  	assert(e);
--- 749,753 ----
  	}
  	break;
!     case power: {
  	expr_ty e = ast_for_atom(CHILD(n, 0));
  	assert(e);
***************
*** 757,763 ****
             trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME */
  	if (TYPE(CHILD(n, NCH(n) - 1)) == factor) {
! 	    /* XXX Handle ** */
! 	    assert(0);
! 	    return NULL;
  	}
  	for (i = 1; i < NCH(n); i++) {
--- 757,762 ----
             trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME */
  	if (TYPE(CHILD(n, NCH(n) - 1)) == factor) {
! 	    expr_ty f = ast_for_expr(CHILD(n, NCH(n) - 1));
! 	    return BinOp(e, Pow, f);
  	}
  	for (i = 1; i < NCH(n); i++) {
***************
*** 793,796 ****
--- 792,798 ----
  	break;
      }
+     default:
+ 	fprintf(stderr, "unhandled expr: %d\n", TYPE(n));
+ 	return NULL;
      }
      /* should never get here */
***************
*** 814,818 ****
  ast_for_testlist(const node *n)
  {
!     /* could be a testlist or a listmaker with no list_for */
      if (NCH(n) == 1)
  	return ast_for_expr(CHILD(n, 0));
--- 816,822 ----
  ast_for_testlist(const node *n)
  {
!     /* n could be a testlist, a listmaker with no list_for, or
!        a testlist1 from inside backquotes. */
!        
      if (NCH(n) == 1)
  	return ast_for_expr(CHILD(n, 0));
***************
*** 1111,1118 ****
      asdl_seq *seq = NULL;
      stmt_ty s;
!     int i, total, num;
      node *ch;
  
!     fprintf(stderr, "ast_for_suite(%d)\n", TYPE(n));
      REQ(n, suite);
  
--- 1115,1122 ----
      asdl_seq *seq = NULL;
      stmt_ty s;
!     int i, total, num, pos = 0;
      node *ch;
  
!     fprintf(stderr, "ast_for_suite(%d) lineno=%d\n", TYPE(n), n->n_lineno);
      REQ(n, suite);
  
***************
*** 1126,1130 ****
  	    if (!s)
  		goto error;
! 	    asdl_seq_APPEND(seq, s);
  	}
      }
--- 1130,1134 ----
  	    if (!s)
  		goto error;
! 	    asdl_seq_SET(seq, pos++, s);
  	}
      }
***************
*** 1139,1143 ****
  		if (!s)
  		    goto error;
! 		asdl_seq_APPEND(seq, s);
  	    }
  	    else {
--- 1143,1147 ----
  		if (!s)
  		    goto error;
! 		asdl_seq_SET(seq, pos++, s);
  	    }
  	    else {
***************
*** 1149,1158 ****
  		    if (!s)
  			goto error;
! 		    asdl_seq_APPEND(seq, s);
  		}
  	    }
  	}
      }
!     assert(seq->size == seq->offset);
      return seq;
   error:
--- 1153,1162 ----
  		    if (!s)
  			goto error;
! 		    asdl_seq_SET(seq, pos++, s);
  		}
  	    }
  	}
      }
!     assert(pos == seq->size);
      return seq;
   error:
***************
*** 1346,1349 ****
--- 1350,1356 ----
  ast_for_stmt(const node *n)
  {
+ /*    _PyObject_DebugMallocStats(); */
+     fprintf(stderr, "ast_for_stmt(%d) lineno=%d\n",
+ 	    TYPE(n), n->n_lineno);
      if (TYPE(n) == stmt) {
  	assert(NCH(n) == 1);