[Python-checkins] python/dist/src/Python ast.c,1.1.2.22,1.1.2.23

jhylton@users.sourceforge.net jhylton@users.sourceforge.net
2003年3月31日 13:40:07 -0800


Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1:/tmp/cvs-serv20160
Modified Files:
 Tag: ast-branch
	ast.c 
Log Message:
Generate valid ast for 1 + 1 + 1, i.e.
when there is more than one operator in a sequence of expressions.
Index: ast.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/ast.c,v
retrieving revision 1.1.2.22
retrieving revision 1.1.2.23
diff -C2 -d -r1.1.2.22 -r1.1.2.23
*** ast.c	28 Mar 2003 19:47:19 -0000	1.1.2.22
--- ast.c	31 Mar 2003 21:40:03 -0000	1.1.2.23
***************
*** 650,653 ****
--- 650,679 ----
 
 static expr_ty
+ ast_for_binop(const node *n)
+ {
+ 	/* Must account for a sequence of expressions.
+ 	 How should A op B op C by represented? 
+ 	 BinOp(BinOp(A, op, B), op, C).
+ 	*/
+ 
+ 	int i, nops;
+ 	expr_ty result;
+ 
+ 	result = BinOp(ast_for_expr(CHILD(n, 0)), get_operator(CHILD(n, 1)),
+ 		 ast_for_expr(CHILD(n, 2)));
+ 	if (!result)
+ 		return NULL;
+ 	nops = (NCH(n) - 1) / 2;
+ 	for (i = 1; i < nops; i++) {
+ 		expr_ty tmp = BinOp(result, get_operator(CHILD(n, i * 2 + 1)),
+ 				 ast_for_expr(CHILD(n, i * 2 + 2)));
+ 		if (!tmp) 
+ 			return NULL;
+ 		result = tmp;
+ 	}
+ 	return result;
+ }
+ 
+ static expr_ty
 ast_for_expr(const node *n)
 {
***************
*** 735,741 ****
 	 goto loop;
 	}
! 	return BinOp(ast_for_expr(CHILD(n, 0)), get_operator(CHILD(n, 1)),
! 		 ast_for_expr(CHILD(n, 2)));
! 	break;
 case factor:
 	if (NCH(n) == 1) {
--- 761,765 ----
 	 goto loop;
 	}
! 	return ast_for_binop(n);
 case factor:
 	if (NCH(n) == 1) {

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