Essential changes for print function changes.

Lib will be changed in a separate run.
This commit is contained in:
Guido van Rossum 2007-02-09 05:32:43 +00:00
parent 21298cfea6
commit 452bf519a7
9 changed files with 1060 additions and 1197 deletions

View File

@ -38,15 +38,13 @@ vfplist: vfpdef (',' vfpdef)* [',']
stmt: simple_stmt | compound_stmt
simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
small_stmt: (expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt |
small_stmt: (expr_stmt | del_stmt | pass_stmt | flow_stmt |
import_stmt | global_stmt | assert_stmt)
expr_stmt: testlist (augassign (yield_expr|testlist) |
('=' (yield_expr|testlist))*)
augassign: ('+=' | '-=' | '*=' | '/=' | '%=' | '&=' | '|=' | '^=' |
'<<=' | '>>=' | '**=' | '//=')
# For normal assignments, additional restrictions enforced by the interpreter
print_stmt: 'print' ( [ test (',' test)* [','] ] |
'>>' test [ (',' test)+ [','] ] )
del_stmt: 'del' exprlist
pass_stmt: 'pass'
flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt

View File

@ -18,71 +18,70 @@
#define small_stmt 273
#define expr_stmt 274
#define augassign 275
#define print_stmt 276
#define del_stmt 277
#define pass_stmt 278
#define flow_stmt 279
#define break_stmt 280
#define continue_stmt 281
#define return_stmt 282
#define yield_stmt 283
#define raise_stmt 284
#define import_stmt 285
#define import_name 286
#define import_from 287
#define import_as_name 288
#define dotted_as_name 289
#define import_as_names 290
#define dotted_as_names 291
#define dotted_name 292
#define global_stmt 293
#define assert_stmt 294
#define compound_stmt 295
#define if_stmt 296
#define while_stmt 297
#define for_stmt 298
#define try_stmt 299
#define with_stmt 300
#define with_var 301
#define except_clause 302
#define suite 303
#define testlist_safe 304
#define old_test 305
#define old_lambdef 306
#define test 307
#define or_test 308
#define and_test 309
#define not_test 310
#define comparison 311
#define comp_op 312
#define expr 313
#define xor_expr 314
#define and_expr 315
#define shift_expr 316
#define arith_expr 317
#define term 318
#define factor 319
#define power 320
#define atom 321
#define listmaker 322
#define testlist_gexp 323
#define lambdef 324
#define trailer 325
#define subscriptlist 326
#define subscript 327
#define sliceop 328
#define exprlist 329
#define testlist 330
#define dictsetmaker 331
#define classdef 332
#define arglist 333
#define argument 334
#define list_iter 335
#define list_for 336
#define list_if 337
#define gen_iter 338
#define gen_for 339
#define gen_if 340
#define testlist1 341
#define encoding_decl 342
#define yield_expr 343
#define del_stmt 276
#define pass_stmt 277
#define flow_stmt 278
#define break_stmt 279
#define continue_stmt 280
#define return_stmt 281
#define yield_stmt 282
#define raise_stmt 283
#define import_stmt 284
#define import_name 285
#define import_from 286
#define import_as_name 287
#define dotted_as_name 288
#define import_as_names 289
#define dotted_as_names 290
#define dotted_name 291
#define global_stmt 292
#define assert_stmt 293
#define compound_stmt 294
#define if_stmt 295
#define while_stmt 296
#define for_stmt 297
#define try_stmt 298
#define with_stmt 299
#define with_var 300
#define except_clause 301
#define suite 302
#define testlist_safe 303
#define old_test 304
#define old_lambdef 305
#define test 306
#define or_test 307
#define and_test 308
#define not_test 309
#define comparison 310
#define comp_op 311
#define expr 312
#define xor_expr 313
#define and_expr 314
#define shift_expr 315
#define arith_expr 316
#define term 317
#define factor 318
#define power 319
#define atom 320
#define listmaker 321
#define testlist_gexp 322
#define lambdef 323
#define trailer 324
#define subscriptlist 325
#define subscript 326
#define sliceop 327
#define exprlist 328
#define testlist 329
#define dictsetmaker 330
#define classdef 331
#define arglist 332
#define argument 333
#define list_iter 334
#define list_for 335
#define list_if 336
#define gen_iter 337
#define gen_for 338
#define gen_if 339
#define testlist1 340
#define encoding_decl 341
#define yield_expr 342

View File

@ -341,7 +341,7 @@ $(BUILDPYTHON): Modules/python.o $(LIBRARY) $(LDLIBRARY)
$(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
platform: $(BUILDPYTHON)
$(RUNSHARED) ./$(BUILDPYTHON) -E -c 'import sys ; from distutils.util import get_platform ; print get_platform()+"-"+sys.version[0:3]' >platform
$(RUNSHARED) ./$(BUILDPYTHON) -E -c 'import sys ; from distutils.util import get_platform ; print(get_platform()+"-"+sys.version[0:3])' >platform
# Build the shared modules

View File

@ -857,7 +857,7 @@ VALIDATER(testlist); VALIDATER(varargslist);
VALIDATER(vfpdef); VALIDATER(vfplist);
VALIDATER(stmt); VALIDATER(simple_stmt);
VALIDATER(expr_stmt); VALIDATER(power);
VALIDATER(print_stmt); VALIDATER(del_stmt);
VALIDATER(del_stmt);
VALIDATER(return_stmt); VALIDATER(list_iter);
VALIDATER(raise_stmt); VALIDATER(import_stmt);
VALIDATER(import_name); VALIDATER(import_from);
@ -1545,7 +1545,6 @@ validate_small_stmt(node *tree)
int ntype = TYPE(CHILD(tree, 0));
if ( (ntype == expr_stmt)
|| (ntype == print_stmt)
|| (ntype == del_stmt)
|| (ntype == pass_stmt)
|| (ntype == flow_stmt)
@ -1650,54 +1649,6 @@ validate_expr_stmt(node *tree)
}
/* print_stmt:
*
* 'print' ( [ test (',' test)* [','] ]
* | '>>' test [ (',' test)+ [','] ] )
*/
static int
validate_print_stmt(node *tree)
{
int nch = NCH(tree);
int res = (validate_ntype(tree, print_stmt)
&& (nch > 0)
&& validate_name(CHILD(tree, 0), "print"));
if (res && nch > 1) {
int sym = TYPE(CHILD(tree, 1));
int i = 1;
int allow_trailing_comma = 1;
if (sym == test)
res = validate_test(CHILD(tree, i++));
else {
if (nch < 3)
res = validate_numnodes(tree, 3, "print_stmt");
else {
res = (validate_ntype(CHILD(tree, i), RIGHTSHIFT)
&& validate_test(CHILD(tree, i+1)));
i += 2;
allow_trailing_comma = 0;
}
}
if (res) {
/* ... (',' test)* [','] */
while (res && i+2 <= nch) {
res = (validate_comma(CHILD(tree, i))
&& validate_test(CHILD(tree, i+1)));
allow_trailing_comma = 1;
i += 2;
}
if (res && !allow_trailing_comma)
res = validate_numnodes(tree, i, "print_stmt");
else if (res && i < nch)
res = validate_comma(CHILD(tree, i));
}
}
return (res);
}
static int
validate_del_stmt(node *tree)
{
@ -2977,7 +2928,7 @@ validate_node(node *tree)
break;
case small_stmt:
/*
* expr_stmt | print_stmt | del_stmt | pass_stmt | flow_stmt
* expr_stmt | del_stmt | pass_stmt | flow_stmt
* | import_stmt | global_stmt | assert_stmt
*/
res = validate_small_stmt(tree);
@ -3012,9 +2963,6 @@ validate_node(node *tree)
case expr_stmt:
res = validate_expr_stmt(tree);
break;
case print_stmt:
res = validate_print_stmt(tree);
break;
case del_stmt:
res = validate_del_stmt(tree);
break;

View File

@ -2218,37 +2218,6 @@ ast_for_expr_stmt(struct compiling *c, const node *n)
}
}
static stmt_ty
ast_for_print_stmt(struct compiling *c, const node *n)
{
/* print_stmt: 'print' ( [ test (',' test)* [','] ]
| '>>' test [ (',' test)+ [','] ] )
*/
expr_ty dest = NULL, expression;
asdl_seq *seq;
bool nl;
int i, j, start = 1;
REQ(n, print_stmt);
if (NCH(n) >= 2 && TYPE(CHILD(n, 1)) == RIGHTSHIFT) {
dest = ast_for_expr(c, CHILD(n, 2));
if (!dest)
return NULL;
start = 4;
}
seq = asdl_seq_new((NCH(n) + 1 - start) / 2, c->c_arena);
if (!seq)
return NULL;
for (i = start, j = 0; i < NCH(n); i += 2, ++j) {
expression = ast_for_expr(c, CHILD(n, i));
if (!expression)
return NULL;
asdl_seq_SET(seq, j, expression);
}
nl = (TYPE(CHILD(n, NCH(n) - 1)) == COMMA) ? false : true;
return Print(dest, seq, nl, LINENO(n), n->n_col_offset, c->c_arena);
}
static asdl_seq *
ast_for_exprlist(struct compiling *c, const node *n, expr_context_ty context)
{
@ -3089,14 +3058,12 @@ ast_for_stmt(struct compiling *c, const node *n)
if (TYPE(n) == small_stmt) {
REQ(n, small_stmt);
n = CHILD(n, 0);
/* small_stmt: expr_stmt | print_stmt | del_stmt | pass_stmt
/* small_stmt: expr_stmt | del_stmt | pass_stmt
| flow_stmt | import_stmt | global_stmt | assert_stmt
*/
switch (TYPE(n)) {
case expr_stmt:
return ast_for_expr_stmt(c, n);
case print_stmt:
return ast_for_print_stmt(c, n);
case del_stmt:
return ast_for_del_stmt(c, n);
case pass_stmt:

View File

@ -1446,7 +1446,7 @@ builtin_print(PyObject *self, PyObject *args, PyObject *kwds)
}
PyDoc_STRVAR(print_doc,
"Print(value, ..., file=None, sep=' ', end='\\n')\n\
"print(value, ..., file=None, sep=' ', end='\\n')\n\
\n\
Prints the values to a stream, or to sys.stdout by default.\n\
Optional keyword arguments:\n\
@ -2056,7 +2056,7 @@ static PyMethodDef builtin_methods[] = {
{"open", (PyCFunction)builtin_open, METH_VARARGS | METH_KEYWORDS, open_doc},
{"ord", builtin_ord, METH_O, ord_doc},
{"pow", builtin_pow, METH_VARARGS, pow_doc},
{"Print", (PyCFunction)builtin_print, METH_VARARGS | METH_KEYWORDS, print_doc},
{"print", (PyCFunction)builtin_print, METH_VARARGS | METH_KEYWORDS, print_doc},
{"range", builtin_range, METH_VARARGS, range_doc},
{"reload", builtin_reload, METH_O, reload_doc},
{"repr", builtin_repr, METH_O, repr_doc},

File diff suppressed because it is too large Load Diff

View File

@ -71,9 +71,10 @@ extern time_t PyOS_GetLastModificationTime(char *, FILE *);
3020 (added BUILD_SET)
3030 (added keyword-only parameters)
3040 (added signature annotations)
3050 (print becomes a function)
.
*/
#define MAGIC (3040 | ((long)'\r'<<16) | ((long)'\n'<<24))
#define MAGIC (3050 | ((long)'\r'<<16) | ((long)'\n'<<24))
/* Magic word as global; note that _PyImport_Init() can change the
value of this global to accommodate for alterations of how the

View File

@ -664,7 +664,7 @@ class PyBuildExt(build_ext):
# search path.
for d in inc_dirs + db_inc_paths:
f = os.path.join(d, "db.h")
if db_setup_debug: print "db: looking for db.h in", f
if db_setup_debug: print("db: looking for db.h in", f)
if os.path.exists(f):
f = open(f).read()
m = re.search(r"#define\WDB_VERSION_MAJOR\W(\d+)", f)
@ -680,13 +680,13 @@ class PyBuildExt(build_ext):
# (first occurrance only)
db_ver_inc_map[db_ver] = d
if db_setup_debug:
print "db.h: found", db_ver, "in", d
print("db.h: found", db_ver, "in", d)
else:
# we already found a header for this library version
if db_setup_debug: print "db.h: ignoring", d
if db_setup_debug: print("db.h: ignoring", d)
else:
# ignore this header, it didn't contain a version number
if db_setup_debug: print "db.h: unsupported version", db_ver, "in", d
if db_setup_debug: print("db.h: unsupported version", db_ver, "in", d)
db_found_vers = db_ver_inc_map.keys()
db_found_vers.sort()
@ -717,12 +717,12 @@ class PyBuildExt(build_ext):
dblib_dir = [ os.path.abspath(os.path.dirname(dblib_file)) ]
raise db_found
else:
if db_setup_debug: print "db lib: ", dblib, "not found"
if db_setup_debug: print("db lib: ", dblib, "not found")
except db_found:
if db_setup_debug:
print "db lib: using", db_ver, dblib
print "db: lib dir", dblib_dir, "inc dir", db_incdir
print("db lib: using", db_ver, dblib)
print("db: lib dir", dblib_dir, "inc dir", db_incdir)
db_incs = [db_incdir]
dblibs = [dblib]
# We add the runtime_library_dirs argument because the
@ -737,7 +737,7 @@ class PyBuildExt(build_ext):
include_dirs=db_incs,
libraries=dblibs))
else:
if db_setup_debug: print "db: no appropriate library found"
if db_setup_debug: print("db: no appropriate library found")
db_incs = None
dblibs = []
dblib_dir = None
@ -765,7 +765,7 @@ class PyBuildExt(build_ext):
for d in inc_dirs + sqlite_inc_paths:
f = os.path.join(d, "sqlite3.h")
if os.path.exists(f):
if sqlite_setup_debug: print "sqlite: found %s"%f
if sqlite_setup_debug: print("sqlite: found %s"%f)
incf = open(f).read()
m = re.search(
r'\s*.*#\s*.*define\s.*SQLITE_VERSION\W*"(.*)"', incf)
@ -776,15 +776,15 @@ class PyBuildExt(build_ext):
if sqlite_version_tuple >= MIN_SQLITE_VERSION_NUMBER:
# we win!
if sqlite_setup_debug:
print "%s/sqlite3.h: version %s"%(d, sqlite_version)
print("%s/sqlite3.h: version %s"%(d, sqlite_version))
sqlite_incdir = d
break
else:
if sqlite_setup_debug:
print "%s: version %d is too old, need >= %s"%(d,
sqlite_version, MIN_SQLITE_VERSION)
print("%s: version %d is too old, need >= %s"%(d,
sqlite_version, MIN_SQLITE_VERSION))
elif sqlite_setup_debug:
print "sqlite: %s had no SQLITE_VERSION"%(f,)
print("sqlite: %s had no SQLITE_VERSION"%(f,))
if sqlite_incdir:
sqlite_dirs_to_check = [
@ -1333,7 +1333,7 @@ class PyBuildExt(build_ext):
res = os.system(cmd)
if res or not os.path.exists(ffi_configfile):
print "Failed to configure _ctypes module"
print("Failed to configure _ctypes module")
return False
fficonfig = {}