[Python-checkins] python/dist/src/Python ast.c,1.1.2.15,1.1.2.16
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Tue, 25 Mar 2003 11:24:46 -0800
Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1:/tmp/cvs-serv12526/Python
Modified Files:
Tag: ast-branch
ast.c
Log Message:
Trimmed trailing whitespace; added a comment for parsestr().
Index: ast.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/ast.c,v
retrieving revision 1.1.2.15
retrieving revision 1.1.2.16
diff -C2 -d -r1.1.2.15 -r1.1.2.16
*** ast.c 25 Mar 2003 19:09:16 -0000 1.1.2.15
--- ast.c 25 Mar 2003 19:24:42 -0000 1.1.2.16
***************
*** 36,44 ****
Use this routine to determine how big a sequence is needed for
the statements in a parse tree. Its raison d'etre is this bit of
! grammar:
stmt: simple_stmt | compound_stmt
simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
!
A simple_stmt can contain multiple small_stmt elements joined
by semicolons. If the arg is a simple_stmt, the number of
--- 36,44 ----
Use this routine to determine how big a sequence is needed for
the statements in a parse tree. Its raison d'etre is this bit of
! grammar:
stmt: simple_stmt | compound_stmt
simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
!
A simple_stmt can contain multiple small_stmt elements joined
by semicolons. If the arg is a simple_stmt, the number of
***************
*** 112,116 ****
if (num == 1) {
s = ast_for_stmt(ch);
! if (!s)
goto error;
asdl_seq_APPEND(stmts, s);
--- 112,116 ----
if (num == 1) {
s = ast_for_stmt(ch);
! if (!s)
goto error;
asdl_seq_APPEND(stmts, s);
***************
*** 160,164 ****
}
}
!
return Interactive(stmts);
}
--- 160,164 ----
}
}
!
return Interactive(stmts);
}
***************
*** 254,260 ****
n = CHILD(n, 0);
switch (STR(n)[0]) {
! case '+':
return Add;
! case '-':
return Sub;
case '/':
--- 254,260 ----
n = CHILD(n, 0);
switch (STR(n)[0]) {
! case '+':
return Add;
! case '-':
return Sub;
case '/':
***************
*** 263,277 ****
else
return Div;
! case '%':
return Mod;
! case '<':
return LShift;
! case '>':
return RShift;
! case '&':
return BitAnd;
! case '^':
return BitXor;
! case '|':
return BitOr;
case '*':
--- 263,277 ----
else
return Div;
! case '%':
return Mod;
! case '<':
return LShift;
! case '>':
return RShift;
! case '&':
return BitAnd;
! case '^':
return BitXor;
! case '|':
return BitOr;
case '*':
***************
*** 296,316 ****
n = CHILD(n, 0);
switch (TYPE(n)) {
! case LESS:
return Lt;
! case GREATER:
return Gt;
case EQEQUAL: /* == */
case EQUAL:
return Eq;
! case LESSEQUAL:
return LtE;
! case GREATEREQUAL:
return GtE;
! case NOTEQUAL:
return NotEq;
! case NAME:
! if (strcmp(STR(n), "in") == 0)
return In;
! if (strcmp(STR(n), "is") == 0)
return Is;
}
--- 296,316 ----
n = CHILD(n, 0);
switch (TYPE(n)) {
! case LESS:
return Lt;
! case GREATER:
return Gt;
case EQEQUAL: /* == */
case EQUAL:
return Eq;
! case LESSEQUAL:
return LtE;
! case GREATEREQUAL:
return GtE;
! case NOTEQUAL:
return NotEq;
! case NAME:
! if (strcmp(STR(n), "in") == 0)
return In;
! if (strcmp(STR(n), "is") == 0)
return Is;
}
***************
*** 319,323 ****
/* handle "not in" and "is not" */
switch (TYPE(CHILD(n, 0))) {
! case NAME:
if (strcmp(STR(CHILD(n, 1)), "in") == 0)
return NotIn;
--- 319,323 ----
/* handle "not in" and "is not" */
switch (TYPE(CHILD(n, 0))) {
! case NAME:
if (strcmp(STR(CHILD(n, 1)), "in") == 0)
return NotIn;
***************
*** 353,357 ****
/* parameters: '(' [varargslist] ')'
! varargslist: (fpdef ['=' test] ',')* ('*' NAME [',' '**' NAME]
| '**' NAME) | fpdef ['=' test] (',' fpdef ['=' test])* [',']
*/
--- 353,357 ----
/* parameters: '(' [varargslist] ')'
! varargslist: (fpdef ['=' test] ',')* ('*' NAME [',' '**' NAME]
| '**' NAME) | fpdef ['=' test] (',' fpdef ['=' test])* [',']
*/
***************
*** 432,436 ****
/* lambdef: 'lambda' [varargslist] ':' test */
if (NCH(n) == 3)
! return Lambda(arguments(NULL, NULL, NULL, NULL),
ast_for_expr(CHILD(n, 2)));
else
--- 432,436 ----
/* lambdef: 'lambda' [varargslist] ':' test */
if (NCH(n) == 3)
! return Lambda(arguments(NULL, NULL, NULL, NULL),
ast_for_expr(CHILD(n, 2)));
else
***************
*** 487,491 ****
ast_for_listcomp(const node *n)
{
! /* listmaker: test ( list_for | (',' test)* [','] )
list_for: 'for' exprlist 'in' testlist_safe [list_iter]
list_iter: list_for | list_if
--- 487,491 ----
ast_for_listcomp(const node *n)
{
! /* listmaker: test ( list_for | (',' test)* [','] )
list_for: 'for' exprlist 'in' testlist_safe [list_iter]
list_iter: list_for | list_if
***************
*** 500,504 ****
REQ(n, listmaker);
assert(NCH(n) > 1);
!
target = ast_for_expr(CHILD(n, 0));
if (!target)
--- 500,504 ----
REQ(n, listmaker);
assert(NCH(n) > 1);
!
target = ast_for_expr(CHILD(n, 0));
if (!target)
***************
*** 515,519 ****
t = ast_for_exprlist(CHILD(ch, 1), Store);
if (asdl_seq_LEN(t) == 1)
! c = listcomp(asdl_seq_GET(t, 0),
ast_for_testlist(CHILD(ch, 3)), NULL);
else
--- 515,519 ----
t = ast_for_exprlist(CHILD(ch, 1), Store);
if (asdl_seq_LEN(t) == 1)
! c = listcomp(asdl_seq_GET(t, 0),
ast_for_testlist(CHILD(ch, 3)), NULL);
else
***************
*** 547,552 ****
ast_for_atom(const node *n)
{
! /* atom: '(' [testlist] ')' | '[' [listmaker] ']'
! | '{' [dictmaker] '}' | '`' testlist '`' | NAME | NUMBER | STRING+
*/
node *ch = CHILD(n, 0);
--- 547,552 ----
ast_for_atom(const node *n)
{
! /* atom: '(' [testlist] ')' | '[' [listmaker] ']'
! | '{' [dictmaker] '}' | '`' testlist '`' | NAME | NUMBER | STRING+
*/
node *ch = CHILD(n, 0);
***************
*** 619,623 ****
if (NCH(n) == 1 && TYPE(ch) == test)
return Index(ast_for_expr(ch));
!
if (TYPE(ch) == test)
lower = ast_for_expr(ch);
--- 619,623 ----
if (NCH(n) == 1 && TYPE(ch) == test)
return Index(ast_for_expr(ch));
!
if (TYPE(ch) == test)
lower = ast_for_expr(ch);
***************
*** 645,649 ****
step = ast_for_expr(ch);
}
!
return Slice(lower, upper, step);
}
--- 645,649 ----
step = ast_for_expr(ch);
}
!
return Slice(lower, upper, step);
}
***************
*** 713,717 ****
for (i = 1; i < NCH(n); i += 2) {
/* XXX cmpop_ty is just an enum */
! asdl_seq_SET(ops, i / 2,
(void *)ast_for_comp_op(CHILD(n, i)));
asdl_seq_SET(cmps, i / 2, ast_for_expr(CHILD(n, i + 1)));
--- 713,717 ----
for (i = 1; i < NCH(n); i += 2) {
/* XXX cmpop_ty is just an enum */
! asdl_seq_SET(ops, i / 2,
(void *)ast_for_comp_op(CHILD(n, i)));
asdl_seq_SET(cmps, i / 2, ast_for_expr(CHILD(n, i + 1)));
***************
*** 760,764 ****
if (NCH(n) == 1)
return e;
! /* power: atom trailer* ('**' factor)*
trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME */
if (TYPE(CHILD(n, NCH(n) - 1)) == factor) {
--- 760,764 ----
if (NCH(n) == 1)
return e;
! /* power: atom trailer* ('**' factor)*
trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME */
if (TYPE(CHILD(n, NCH(n) - 1)) == factor) {
***************
*** 784,788 ****
asdl_seq *slices = asdl_seq_new(NCH(ch) / 2);
for (j = 0; j < NCH(ch); j += 2)
! asdl_seq_SET(slices, j / 2,
ast_for_slice(CHILD(ch, j)));
new = Subscript(e, ExtSlice(slices), Load);
--- 784,788 ----
asdl_seq *slices = asdl_seq_new(NCH(ch) / 2);
for (j = 0; j < NCH(ch); j += 2)
! asdl_seq_SET(slices, j / 2,
ast_for_slice(CHILD(ch, j)));
new = Subscript(e, ExtSlice(slices), Load);
***************
*** 806,814 ****
}
! static expr_ty
ast_for_call(const node *n, expr_ty func)
{
/*
! arglist: (argument ',')* (argument [',']| '*' test [',' '**' test]
| '**' test)
argument: [test '='] test # Really [keyword '='] test
--- 806,814 ----
}
! static expr_ty
ast_for_call(const node *n, expr_ty func)
{
/*
! arglist: (argument ',')* (argument [',']| '*' test [',' '**' test]
| '**' test)
argument: [test '='] test # Really [keyword '='] test
***************
*** 837,841 ****
}
}
!
/* XXX syntax error if more than 255 arguments */
--- 837,841 ----
}
}
!
/* XXX syntax error if more than 255 arguments */
***************
*** 848,855 ****
/* 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));
! else
return Tuple(seq_for_testlist(n), Load);
}
--- 848,855 ----
/* 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));
! else
return Tuple(seq_for_testlist(n), Load);
}
***************
*** 859,867 ****
{
REQ(n, expr_stmt);
! /* expr_stmt: testlist (augassign testlist | ('=' testlist)*)
testlist: test (',' test)* [',']
! augassign: '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^='
| '<<=' | '>>=' | '**=' | '//='
! test: ... here starts the operator precendence dance
*/
--- 859,867 ----
{
REQ(n, expr_stmt);
! /* expr_stmt: testlist (augassign testlist | ('=' testlist)*)
testlist: test (',' test)* [',']
! augassign: '+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^='
| '<<=' | '>>=' | '**=' | '//='
! test: ... here starts the operator precendence dance
*/
***************
*** 900,905 ****
ast_for_print_stmt(const node *n)
{
! /* print_stmt: 'print' ( [ test (',' test)* [','] ]
! | '>>' test [ (',' test)+ [','] ] )
*/
expr_ty dest = NULL;
--- 900,905 ----
ast_for_print_stmt(const node *n)
{
! /* print_stmt: 'print' ( [ test (',' test)* [','] ]
! | '>>' test [ (',' test)+ [','] ] )
*/
expr_ty dest = NULL;
***************
*** 955,959 ****
{
/*
! flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt
| yield_stmt
break_stmt: 'break'
--- 955,959 ----
{
/*
! flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt
| yield_stmt
break_stmt: 'break'
***************
*** 985,994 ****
return Raise(ast_for_expr(CHILD(n, 1)), NULL, NULL, LINENO(n));
else if (NCH(ch) == 4)
! return Raise(ast_for_expr(CHILD(n, 1)),
! ast_for_expr(CHILD(n, 3)),
NULL, LINENO(n));
else if (NCH(ch) == 6)
! return Raise(ast_for_expr(CHILD(n, 1)),
! ast_for_expr(CHILD(n, 3)),
ast_for_expr(CHILD(n, 5)), LINENO(n));
default:
--- 985,994 ----
return Raise(ast_for_expr(CHILD(n, 1)), NULL, NULL, LINENO(n));
else if (NCH(ch) == 4)
! return Raise(ast_for_expr(CHILD(n, 1)),
! ast_for_expr(CHILD(n, 3)),
NULL, LINENO(n));
else if (NCH(ch) == 6)
! return Raise(ast_for_expr(CHILD(n, 1)),
! ast_for_expr(CHILD(n, 3)),
ast_for_expr(CHILD(n, 5)), LINENO(n));
default:
***************
*** 1037,1041 ****
len = 0;
! for (i = 0; i < NCH(n); i += 2)
/* length of string plus one for the dot */
len += strlen(STR(CHILD(n, i))) + 1;
--- 1037,1041 ----
len = 0;
! for (i = 0; i < NCH(n); i += 2)
/* length of string plus one for the dot */
len += strlen(STR(CHILD(n, i))) + 1;
***************
*** 1067,1072 ****
{
/*
! import_stmt: 'import' dotted_as_name (',' dotted_as_name)*
! | 'from' dotted_name 'import' ('*'
| import_as_name (',' import_as_name)*)
*/
--- 1067,1072 ----
{
/*
! import_stmt: 'import' dotted_as_name (',' dotted_as_name)*
! | 'from' dotted_name 'import' ('*'
| import_as_name (',' import_as_name)*)
*/
***************
*** 1117,1124 ****
return Exec(ast_for_expr(CHILD(n, 1)), NULL, NULL, LINENO(n));
else if (NCH(n) == 4)
! return Exec(ast_for_expr(CHILD(n, 1)),
ast_for_expr(CHILD(n, 3)), NULL, LINENO(n));
else if (NCH(n) == 6)
! return Exec(ast_for_expr(CHILD(n, 1)),
ast_for_expr(CHILD(n, 3)),
ast_for_expr(CHILD(n, 5)), LINENO(n));
--- 1117,1124 ----
return Exec(ast_for_expr(CHILD(n, 1)), NULL, NULL, LINENO(n));
else if (NCH(n) == 4)
! return Exec(ast_for_expr(CHILD(n, 1)),
ast_for_expr(CHILD(n, 3)), NULL, LINENO(n));
else if (NCH(n) == 6)
! return Exec(ast_for_expr(CHILD(n, 1)),
ast_for_expr(CHILD(n, 3)),
ast_for_expr(CHILD(n, 5)), LINENO(n));
***************
*** 1199,1203 ****
ast_for_if_stmt(const node *n)
{
! /* if_stmt: 'if' test ':' suite ('elif' test ':' suite)*
['else' ':' suite]
*/
--- 1199,1203 ----
ast_for_if_stmt(const node *n)
{
! /* if_stmt: 'if' test ':' suite ('elif' test ':' suite)*
['else' ':' suite]
*/
***************
*** 1210,1218 ****
ast_for_suite(CHILD(n, 3)), NULL, LINENO(n));
s = STR(CHILD(n, 4));
! /* s[2], the third character in the string, will be
's' for el_s_e, or
'i' for el_i_f
*/
! if (s[2] == 's')
return If(ast_for_expr(CHILD(n, 1)),
ast_for_suite(CHILD(n, 3)),
--- 1210,1218 ----
ast_for_suite(CHILD(n, 3)), NULL, LINENO(n));
s = STR(CHILD(n, 4));
! /* s[2], the third character in the string, will be
's' for el_s_e, or
'i' for el_i_f
*/
! if (s[2] == 's')
return If(ast_for_expr(CHILD(n, 1)),
ast_for_suite(CHILD(n, 3)),
***************
*** 1222,1226 ****
asdl_seq *orelse = NULL;
n_elif = NCH(n) - 4;
! if (TYPE(CHILD(n, n_elif)) == NAME
&& STR(CHILD(n, n_elif))[2] == 's') {
has_else = 1;
--- 1222,1226 ----
asdl_seq *orelse = NULL;
n_elif = NCH(n) - 4;
! if (TYPE(CHILD(n, n_elif)) == NAME
&& STR(CHILD(n, n_elif))[2] == 's') {
has_else = 1;
***************
*** 1234,1238 ****
If(ast_for_expr(CHILD(n, NCH(n) - 6)),
ast_for_suite(CHILD(n, NCH(n) - 4)),
! ast_for_suite(CHILD(n, NCH(n) - 1)),
LINENO(n)));
/* the just-created orelse handled the last elif */
--- 1234,1238 ----
If(ast_for_expr(CHILD(n, NCH(n) - 6)),
ast_for_suite(CHILD(n, NCH(n) - 4)),
! ast_for_suite(CHILD(n, NCH(n) - 1)),
LINENO(n)));
/* the just-created orelse handled the last elif */
***************
*** 1240,1244 ****
} else
orelse = NULL;
!
for (i = 0; i < n_elif; i++) {
int off = 5 + (n_elif - i - 1) * 4;
--- 1240,1244 ----
} else
orelse = NULL;
!
for (i = 0; i < n_elif; i++) {
int off = 5 + (n_elif - i - 1) * 4;
***************
*** 1254,1258 ****
orelse, LINENO(n));
}
!
return NULL;
}
--- 1254,1258 ----
orelse, LINENO(n));
}
!
return NULL;
}
***************
*** 1269,1273 ****
else
return While(ast_for_expr(CHILD(n, 1)),
! ast_for_suite(CHILD(n, 3)),
ast_for_suite(CHILD(n, 6)), LINENO(n));
--- 1269,1273 ----
else
return While(ast_for_expr(CHILD(n, 1)),
! ast_for_suite(CHILD(n, 3)),
ast_for_suite(CHILD(n, 6)), LINENO(n));
***************
*** 1311,1315 ****
return excepthandler(NULL, NULL, ast_for_suite(body));
else if (NCH(exc) == 2)
! return excepthandler(ast_for_expr(CHILD(exc, 1)), NULL,
ast_for_suite(body));
else {
--- 1311,1315 ----
return excepthandler(NULL, NULL, ast_for_suite(body));
else if (NCH(exc) == 2)
! return excepthandler(ast_for_expr(CHILD(exc, 1)), NULL,
ast_for_suite(body));
else {
***************
*** 1332,1337 ****
ast_for_suite(CHILD(n, 5)), LINENO(n));
} else {
! /* try_stmt: ('try' ':' suite (except_clause ':' suite)+
! ['else' ':' suite]
*/
asdl_seq *handlers;
--- 1332,1337 ----
ast_for_suite(CHILD(n, 5)), LINENO(n));
} else {
! /* try_stmt: ('try' ':' suite (except_clause ':' suite)+
! ['else' ':' suite]
*/
asdl_seq *handlers;
***************
*** 1361,1365 ****
asdl_seq *bases;
REQ(n, classdef);
! if (NCH(n) == 4)
return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), NULL,
ast_for_suite(CHILD(n, 3)), LINENO(n));
--- 1361,1365 ----
asdl_seq *bases;
REQ(n, classdef);
! if (NCH(n) == 4)
return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), NULL,
ast_for_suite(CHILD(n, 3)), LINENO(n));
***************
*** 1393,1398 ****
REQ(n, small_stmt);
n = CHILD(n, 0);
! /* small_stmt: expr_stmt | print_stmt | del_stmt | pass_stmt
! | flow_stmt | import_stmt | global_stmt | exec_stmt
| assert_stmt
*/
--- 1393,1398 ----
REQ(n, small_stmt);
n = CHILD(n, 0);
! /* small_stmt: expr_stmt | print_stmt | del_stmt | pass_stmt
! | flow_stmt | import_stmt | global_stmt | exec_stmt
| assert_stmt
*/
***************
*** 1420,1424 ****
}
} else {
! /* compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt
| funcdef | classdef
*/
--- 1420,1424 ----
}
} else {
! /* compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt
| funcdef | classdef
*/
***************
*** 1492,1495 ****
--- 1492,1499 ----
}
+ /* s is a Python string literal, including the bracketing quote characters,
+ * and r &/or u prefixes (if any), and embedded escape sequences (if any).
+ * parsestr parses it, and returns the decoded Python string object.
+ */
static PyObject *
parsestr(const char *s)
***************
*** 1523,1527 ****
len = strlen(s);
if (len > INT_MAX) {
! PyErr_SetString(PyExc_OverflowError,
"string to parse is too long");
return NULL;
--- 1527,1531 ----
len = strlen(s);
if (len > INT_MAX) {
! PyErr_SetString(PyExc_OverflowError,
"string to parse is too long");
return NULL;
***************
*** 1548,1552 ****
s, len, NULL);
return v;
!
}
#endif
--- 1552,1556 ----
s, len, NULL);
return v;
!
}
#endif
***************
*** 1588,1592 ****
break;
case 'x':
! if (isxdigit(Py_CHARMASK(s[0]))
&& isxdigit(Py_CHARMASK(s[1]))) {
unsigned int x = 0;
--- 1592,1596 ----
break;
case 'x':
! if (isxdigit(Py_CHARMASK(s[0]))
&& isxdigit(Py_CHARMASK(s[1]))) {
unsigned int x = 0;
***************
*** 1612,1616 ****
}
Py_DECREF(v);
! PyErr_SetString(PyExc_ValueError,
"invalid \\x escape");
return NULL;
--- 1616,1620 ----
}
Py_DECREF(v);
! PyErr_SetString(PyExc_ValueError,
"invalid \\x escape");
return NULL;