Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(49358)

Delta Between Two Patch Sets: Python/symtable.c

Issue 11619: On Windows, don't encode filenames in the import machinery
Left Patch Set: Created 8 years, 5 months ago
Right Patch Set: Created 6 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Python/pythonrun.c ('k') | Python/_warnings.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #include "Python.h" 1 #include "Python.h"
2 #include "Python-ast.h" 2 #include "Python-ast.h"
3 #include "code.h" 3 #include "code.h"
4 #include "symtable.h" 4 #include "symtable.h"
5 #include "structmember.h" 5 #include "structmember.h"
6 6
7 /* error strings used for warnings */ 7 /* error strings used for warnings */
8 #define GLOBAL_AFTER_ASSIGN \ 8 #define GLOBAL_AFTER_ASSIGN \
9 "name '%.400s' is assigned to before global declaration" 9 "name '%.400s' is assigned to before global declaration"
10 10
11 #define NONLOCAL_AFTER_ASSIGN \ 11 #define NONLOCAL_AFTER_ASSIGN \
12 "name '%.400s' is assigned to before nonlocal declaration" 12 "name '%.400s' is assigned to before nonlocal declaration"
13 13
14 #define GLOBAL_AFTER_USE \ 14 #define GLOBAL_AFTER_USE \
15 "name '%.400s' is used prior to global declaration" 15 "name '%.400s' is used prior to global declaration"
16 16
17 #define NONLOCAL_AFTER_USE \ 17 #define NONLOCAL_AFTER_USE \
18 "name '%.400s' is used prior to nonlocal declaration" 18 "name '%.400s' is used prior to nonlocal declaration"
19 19
20 #define IMPORT_STAR_WARNING "import * only allowed at module level" 20 #define IMPORT_STAR_WARNING "import * only allowed at module level"
21 21
22 #define RETURN_VAL_IN_GENERATOR \
23 "'return' with argument inside generator"
24
25
26 static PySTEntryObject * 22 static PySTEntryObject *
27 ste_new(struct symtable *st, identifier name, _Py_block_ty block, 23 ste_new(struct symtable *st, identifier name, _Py_block_ty block,
28 void *key, int lineno, int col_offset) 24 void *key, int lineno, int col_offset)
29 { 25 {
30 PySTEntryObject *ste = NULL; 26 PySTEntryObject *ste = NULL;
31 PyObject *k; 27 PyObject *k = NULL;
32 28
33 k = PyLong_FromVoidPtr(key); 29 k = PyLong_FromVoidPtr(key);
34 if (k == NULL) 30 if (k == NULL)
35 goto fail; 31 goto fail;
36 ste = PyObject_New(PySTEntryObject, &PySTEntry_Type); 32 ste = PyObject_New(PySTEntryObject, &PySTEntry_Type);
37 if (ste == NULL) 33 if (ste == NULL) {
34 Py_DECREF(k);
38 goto fail; 35 goto fail;
36 }
39 ste->ste_table = st; 37 ste->ste_table = st;
40 ste->ste_id = k; 38 ste->ste_id = k; /* ste owns reference to k */
41 39
40 Py_INCREF(name);
42 ste->ste_name = name; 41 ste->ste_name = name;
43 Py_INCREF(name);
44 42
45 ste->ste_symbols = NULL; 43 ste->ste_symbols = NULL;
46 ste->ste_varnames = NULL; 44 ste->ste_varnames = NULL;
47 ste->ste_children = NULL; 45 ste->ste_children = NULL;
48 46
49 ste->ste_symbols = PyDict_New(); 47 ste->ste_directives = NULL;
50 if (ste->ste_symbols == NULL)
51 goto fail;
52
53 ste->ste_varnames = PyList_New(0);
54 if (ste->ste_varnames == NULL)
55 goto fail;
56
57 ste->ste_children = PyList_New(0);
58 if (ste->ste_children == NULL)
59 goto fail;
60 48
61 ste->ste_type = block; 49 ste->ste_type = block;
62 ste->ste_unoptimized = 0; 50 ste->ste_unoptimized = 0;
63 ste->ste_nested = 0; 51 ste->ste_nested = 0;
64 ste->ste_free = 0; 52 ste->ste_free = 0;
65 ste->ste_varargs = 0; 53 ste->ste_varargs = 0;
66 ste->ste_varkeywords = 0; 54 ste->ste_varkeywords = 0;
67 ste->ste_opt_lineno = 0; 55 ste->ste_opt_lineno = 0;
68 ste->ste_opt_col_offset = 0; 56 ste->ste_opt_col_offset = 0;
69 ste->ste_tmpname = 0; 57 ste->ste_tmpname = 0;
70 ste->ste_lineno = lineno; 58 ste->ste_lineno = lineno;
71 ste->ste_col_offset = col_offset; 59 ste->ste_col_offset = col_offset;
72 60
73 if (st->st_cur != NULL && 61 if (st->st_cur != NULL &&
74 (st->st_cur->ste_nested || 62 (st->st_cur->ste_nested ||
75 st->st_cur->ste_type == FunctionBlock)) 63 st->st_cur->ste_type == FunctionBlock))
76 ste->ste_nested = 1; 64 ste->ste_nested = 1;
77 ste->ste_child_free = 0; 65 ste->ste_child_free = 0;
78 ste->ste_generator = 0; 66 ste->ste_generator = 0;
79 ste->ste_returns_value = 0; 67 ste->ste_returns_value = 0;
68 ste->ste_needs_class_closure = 0;
69
70 ste->ste_symbols = PyDict_New();
71 ste->ste_varnames = PyList_New(0);
72 ste->ste_children = PyList_New(0);
73 if (ste->ste_symbols == NULL
74 || ste->ste_varnames == NULL
75 || ste->ste_children == NULL)
76 goto fail;
80 77
81 if (PyDict_SetItem(st->st_blocks, ste->ste_id, (PyObject *)ste) < 0) 78 if (PyDict_SetItem(st->st_blocks, ste->ste_id, (PyObject *)ste) < 0)
82 goto fail; 79 goto fail;
83 80
84 return ste; 81 return ste;
85 fail: 82 fail:
86 Py_XDECREF(ste); 83 Py_XDECREF(ste);
87 return NULL; 84 return NULL;
88 } 85 }
89 86
90 static PyObject * 87 static PyObject *
91 ste_repr(PySTEntryObject *ste) 88 ste_repr(PySTEntryObject *ste)
92 { 89 {
93 return PyUnicode_FromFormat("<symtable entry %U(%ld), line %d>", 90 return PyUnicode_FromFormat("<symtable entry %U(%ld), line %d>",
94 ste->ste_name, 91 ste->ste_name,
95 PyLong_AS_LONG(ste->ste_id), ste->ste_lineno); 92 PyLong_AS_LONG(ste->ste_id), ste->ste_lineno);
96 } 93 }
97 94
98 static void 95 static void
99 ste_dealloc(PySTEntryObject *ste) 96 ste_dealloc(PySTEntryObject *ste)
100 { 97 {
101 ste->ste_table = NULL; 98 ste->ste_table = NULL;
102 Py_XDECREF(ste->ste_id); 99 Py_XDECREF(ste->ste_id);
103 Py_XDECREF(ste->ste_name); 100 Py_XDECREF(ste->ste_name);
104 Py_XDECREF(ste->ste_symbols); 101 Py_XDECREF(ste->ste_symbols);
105 Py_XDECREF(ste->ste_varnames); 102 Py_XDECREF(ste->ste_varnames);
106 Py_XDECREF(ste->ste_children); 103 Py_XDECREF(ste->ste_children);
104 Py_XDECREF(ste->ste_directives);
107 PyObject_Del(ste); 105 PyObject_Del(ste);
108 } 106 }
109 107
110 #define OFF(x) offsetof(PySTEntryObject, x) 108 #define OFF(x) offsetof(PySTEntryObject, x)
111 109
112 static PyMemberDef ste_memberlist[] = { 110 static PyMemberDef ste_memberlist[] = {
113 {"id", T_OBJECT, OFF(ste_id), READONLY}, 111 {"id", T_OBJECT, OFF(ste_id), READONLY},
114 {"name", T_OBJECT, OFF(ste_name), READONLY}, 112 {"name", T_OBJECT, OFF(ste_name), READONLY},
115 {"symbols", T_OBJECT, OFF(ste_symbols), READONLY}, 113 {"symbols", T_OBJECT, OFF(ste_symbols), READONLY},
116 {"varnames", T_OBJECT, OFF(ste_varnames), READONLY}, 114 {"varnames", T_OBJECT, OFF(ste_varnames), READONLY},
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 static int symtable_visit_arguments(struct symtable *st, arguments_ty); 176 static int symtable_visit_arguments(struct symtable *st, arguments_ty);
179 static int symtable_visit_excepthandler(struct symtable *st, excepthandler_ty); 177 static int symtable_visit_excepthandler(struct symtable *st, excepthandler_ty);
180 static int symtable_visit_alias(struct symtable *st, alias_ty); 178 static int symtable_visit_alias(struct symtable *st, alias_ty);
181 static int symtable_visit_comprehension(struct symtable *st, comprehension_ty); 179 static int symtable_visit_comprehension(struct symtable *st, comprehension_ty);
182 static int symtable_visit_keyword(struct symtable *st, keyword_ty); 180 static int symtable_visit_keyword(struct symtable *st, keyword_ty);
183 static int symtable_visit_slice(struct symtable *st, slice_ty); 181 static int symtable_visit_slice(struct symtable *st, slice_ty);
184 static int symtable_visit_params(struct symtable *st, asdl_seq *args); 182 static int symtable_visit_params(struct symtable *st, asdl_seq *args);
185 static int symtable_visit_argannotations(struct symtable *st, asdl_seq *args); 183 static int symtable_visit_argannotations(struct symtable *st, asdl_seq *args);
186 static int symtable_implicit_arg(struct symtable *st, int pos); 184 static int symtable_implicit_arg(struct symtable *st, int pos);
187 static int symtable_visit_annotations(struct symtable *st, stmt_ty s); 185 static int symtable_visit_annotations(struct symtable *st, stmt_ty s);
186 static int symtable_visit_withitem(struct symtable *st, withitem_ty item);
188 187
189 188
190 static identifier top = NULL, lambda = NULL, genexpr = NULL, 189 static identifier top = NULL, lambda = NULL, genexpr = NULL,
191 listcomp = NULL, setcomp = NULL, dictcomp = NULL, 190 listcomp = NULL, setcomp = NULL, dictcomp = NULL,
192 __class__ = NULL, __locals__ = NULL; 191 __class__ = NULL;
193 192
194 #define GET_IDENTIFIER(VAR) \ 193 #define GET_IDENTIFIER(VAR) \
195 ((VAR) ? (VAR) : ((VAR) = PyUnicode_InternFromString(# VAR))) 194 ((VAR) ? (VAR) : ((VAR) = PyUnicode_InternFromString(# VAR)))
196 195
197 #define DUPLICATE_ARGUMENT \ 196 #define DUPLICATE_ARGUMENT \
198 "duplicate argument '%U' in function definition" 197 "duplicate argument '%U' in function definition"
199 198
200 static struct symtable * 199 static struct symtable *
201 symtable_new(void) 200 symtable_new(void)
202 { 201 {
(...skipping 11 matching lines...) Expand all
214 if ((st->st_blocks = PyDict_New()) == NULL) 213 if ((st->st_blocks = PyDict_New()) == NULL)
215 goto fail; 214 goto fail;
216 st->st_cur = NULL; 215 st->st_cur = NULL;
217 st->st_private = NULL; 216 st->st_private = NULL;
218 return st; 217 return st;
219 fail: 218 fail:
220 PySymtable_Free(st); 219 PySymtable_Free(st);
221 return NULL; 220 return NULL;
222 } 221 }
223 222
223 /* When compiling the use of C stack is probably going to be a lot
224 lighter than when executing Python code but still can overflow
225 and causing a Python crash if not checked (e.g. eval("()"*300000)).
226 Using the current recursion limit for the compiler seems too
227 restrictive (it caused at least one test to fail) so a factor is
228 used to allow deeper recursion when compiling an expression.
229
230 Using a scaling factor means this should automatically adjust when
231 the recursion limit is adjusted for small or large C stack allocations.
232 */
233 #define COMPILER_STACK_FRAME_SCALE 3
234
224 struct symtable * 235 struct symtable *
225 PySymtable_BuildObject(mod_ty mod, PyObject *filename, PyFutureFeatures *future) 236 PySymtable_BuildObject(mod_ty mod, PyObject *filename, PyFutureFeatures *future)
226 { 237 {
227 struct symtable *st = symtable_new(); 238 struct symtable *st = symtable_new();
228 asdl_seq *seq; 239 asdl_seq *seq;
229 int i; 240 int i;
241 PyThreadState *tstate;
230 242
231 if (st == NULL) 243 if (st == NULL)
232 return NULL; 244 return NULL;
245 if (filename == NULL) {
246 PySymtable_Free(st);
247 return NULL;
248 }
233 Py_INCREF(filename); 249 Py_INCREF(filename);
234 st->st_filename = filename; 250 st->st_filename = filename;
235 if (st->st_filename == NULL) { 251 st->st_future = future;
252
253 /* Setup recursion depth check counters */
254 tstate = PyThreadState_GET();
255 if (!tstate) {
236 PySymtable_Free(st); 256 PySymtable_Free(st);
237 return NULL; 257 return NULL;
238 } 258 }
239 st->st_future = future; 259 st->recursion_depth = tstate->recursion_depth * COMPILER_STACK_FRAME_SCALE;
260 st->recursion_limit = Py_GetRecursionLimit() * COMPILER_STACK_FRAME_SCALE;
261
240 /* Make the initial symbol information gathering pass */ 262 /* Make the initial symbol information gathering pass */
241 if (!GET_IDENTIFIER(top) || 263 if (!GET_IDENTIFIER(top) ||
242 !symtable_enter_block(st, top, ModuleBlock, (void *)mod, 0, 0)) { 264 !symtable_enter_block(st, top, ModuleBlock, (void *)mod, 0, 0)) {
243 PySymtable_Free(st); 265 PySymtable_Free(st);
244 return NULL; 266 return NULL;
245 } 267 }
246 268
247 st->st_top = st->st_cur; 269 st->st_top = st->st_cur;
248 st->st_cur->ste_unoptimized = OPT_TOPLEVEL; 270 st->st_cur->ste_unoptimized = OPT_TOPLEVEL;
249 switch (mod->kind) { 271 switch (mod->kind) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 int 354 int
333 PyST_GetScope(PySTEntryObject *ste, PyObject *name) 355 PyST_GetScope(PySTEntryObject *ste, PyObject *name)
334 { 356 {
335 PyObject *v = PyDict_GetItem(ste->ste_symbols, name); 357 PyObject *v = PyDict_GetItem(ste->ste_symbols, name);
336 if (!v) 358 if (!v)
337 return 0; 359 return 0;
338 assert(PyLong_Check(v)); 360 assert(PyLong_Check(v));
339 return (PyLong_AS_LONG(v) >> SCOPE_OFFSET) & SCOPE_MASK; 361 return (PyLong_AS_LONG(v) >> SCOPE_OFFSET) & SCOPE_MASK;
340 } 362 }
341 363
364 static int
365 error_at_directive(PySTEntryObject *ste, PyObject *name)
366 {
367 Py_ssize_t i;
368 PyObject *data;
369 assert(ste->ste_directives);
370 for (i = 0; ; i++) {
371 data = PyList_GET_ITEM(ste->ste_directives, i);
372 assert(PyTuple_CheckExact(data));
373 if (PyTuple_GET_ITEM(data, 0) == name)
374 break;
375 }
376 PyErr_SyntaxLocationObject(ste->ste_table->st_filename,
377 PyLong_AsLong(PyTuple_GET_ITEM(data, 1)),
378 PyLong_AsLong(PyTuple_GET_ITEM(data, 2)));
379 return 0;
380 }
381
342 382
343 /* Analyze raw symbol information to determine scope of each name. 383 /* Analyze raw symbol information to determine scope of each name.
344 384
345 The next several functions are helpers for symtable_analyze(), 385 The next several functions are helpers for symtable_analyze(),
346 which determines whether a name is local, global, or free. In addition, 386 which determines whether a name is local, global, or free. In addition,
347 it determines which local variables are cell variables; they provide 387 it determines which local variables are cell variables; they provide
348 bindings that are used for free variables in enclosed blocks. 388 bindings that are used for free variables in enclosed blocks.
349 389
350 There are also two kinds of global variables, implicit and explicit. An 390 There are also two kinds of global variables, implicit and explicit. An
351 explicit global is declared with the global statement. An implicit 391 explicit global is declared with the global statement. An implicit
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 static int 446 static int
407 analyze_name(PySTEntryObject *ste, PyObject *scopes, PyObject *name, long flags, 447 analyze_name(PySTEntryObject *ste, PyObject *scopes, PyObject *name, long flags,
408 PyObject *bound, PyObject *local, PyObject *free, 448 PyObject *bound, PyObject *local, PyObject *free,
409 PyObject *global) 449 PyObject *global)
410 { 450 {
411 if (flags & DEF_GLOBAL) { 451 if (flags & DEF_GLOBAL) {
412 if (flags & DEF_PARAM) { 452 if (flags & DEF_PARAM) {
413 PyErr_Format(PyExc_SyntaxError, 453 PyErr_Format(PyExc_SyntaxError,
414 "name '%U' is parameter and global", 454 "name '%U' is parameter and global",
415 name); 455 name);
416 PyErr_SyntaxLocationObject(ste->ste_table->st_filename, 456 return error_at_directive(ste, name);
417 ste->ste_lineno, ste->ste_col_offset);
418
419 return 0;
420 } 457 }
421 if (flags & DEF_NONLOCAL) { 458 if (flags & DEF_NONLOCAL) {
422 PyErr_Format(PyExc_SyntaxError, 459 PyErr_Format(PyExc_SyntaxError,
423 "name '%U' is nonlocal and global", 460 "name '%U' is nonlocal and global",
424 name); 461 name);
425 return 0; 462 return error_at_directive(ste, name);
426 } 463 }
427 SET_SCOPE(scopes, name, GLOBAL_EXPLICIT); 464 SET_SCOPE(scopes, name, GLOBAL_EXPLICIT);
428 if (PySet_Add(global, name) < 0) 465 if (PySet_Add(global, name) < 0)
429 return 0; 466 return 0;
430 if (bound && (PySet_Discard(bound, name) < 0)) 467 if (bound && (PySet_Discard(bound, name) < 0))
431 return 0; 468 return 0;
432 return 1; 469 return 1;
433 } 470 }
434 if (flags & DEF_NONLOCAL) { 471 if (flags & DEF_NONLOCAL) {
435 if (flags & DEF_PARAM) { 472 if (flags & DEF_PARAM) {
436 PyErr_Format(PyExc_SyntaxError, 473 PyErr_Format(PyExc_SyntaxError,
437 "name '%U' is parameter and nonlocal", 474 "name '%U' is parameter and nonlocal",
438 name); 475 name);
439 return 0; 476 return error_at_directive(ste, name);
440 } 477 }
441 if (!bound) { 478 if (!bound) {
442 PyErr_Format(PyExc_SyntaxError, 479 PyErr_Format(PyExc_SyntaxError,
443 "nonlocal declaration not allowed at module level"); 480 "nonlocal declaration not allowed at module level");
444 return 0; 481 return error_at_directive(ste, name);
445 } 482 }
446 if (!PySet_Contains(bound, name)) { 483 if (!PySet_Contains(bound, name)) {
447 PyErr_Format(PyExc_SyntaxError, 484 PyErr_Format(PyExc_SyntaxError,
448 "no binding for nonlocal '%U' found", 485 "no binding for nonlocal '%U' found",
449 name); 486 name);
450 487
451 return 0; 488 return error_at_directive(ste, name);
452 } 489 }
453 SET_SCOPE(scopes, name, FREE); 490 SET_SCOPE(scopes, name, FREE);
454 ste->ste_free = 1; 491 ste->ste_free = 1;
455 return PySet_Add(free, name) >= 0; 492 return PySet_Add(free, name) >= 0;
456 } 493 }
457 if (flags & DEF_BOUND) { 494 if (flags & DEF_BOUND) {
458 SET_SCOPE(scopes, name, LOCAL); 495 SET_SCOPE(scopes, name, LOCAL);
459 if (PySet_Add(local, name) < 0) 496 if (PySet_Add(local, name) < 0)
460 return 0; 497 return 0;
461 if (PySet_Discard(global, name) < 0) 498 if (PySet_Discard(global, name) < 0)
(...skipping 24 matching lines...) Expand all
486 } 523 }
487 524
488 #undef SET_SCOPE 525 #undef SET_SCOPE
489 526
490 /* If a name is defined in free and also in locals, then this block 527 /* If a name is defined in free and also in locals, then this block
491 provides the binding for the free variable. The name should be 528 provides the binding for the free variable. The name should be
492 marked CELL in this block and removed from the free list. 529 marked CELL in this block and removed from the free list.
493 530
494 Note that the current block's free variables are included in free. 531 Note that the current block's free variables are included in free.
495 That's safe because no name can be free and local in the same scope. 532 That's safe because no name can be free and local in the same scope.
496
497 The 'restricted' argument may be set to a string to restrict the analysis
498 to the one variable whose name equals that string (e.g. "__class__").
499 */ 533 */
500 534
501 static int 535 static int
502 analyze_cells(PyObject *scopes, PyObject *free, const char *restricted) 536 analyze_cells(PyObject *scopes, PyObject *free)
503 { 537 {
504 PyObject *name, *v, *v_cell; 538 PyObject *name, *v, *v_cell;
505 int success = 0; 539 int success = 0;
506 Py_ssize_t pos = 0; 540 Py_ssize_t pos = 0;
507 541
508 v_cell = PyLong_FromLong(CELL); 542 v_cell = PyLong_FromLong(CELL);
509 if (!v_cell) 543 if (!v_cell)
510 return 0; 544 return 0;
511 while (PyDict_Next(scopes, &pos, &name, &v)) { 545 while (PyDict_Next(scopes, &pos, &name, &v)) {
512 long scope; 546 long scope;
513 assert(PyLong_Check(v)); 547 assert(PyLong_Check(v));
514 scope = PyLong_AS_LONG(v); 548 scope = PyLong_AS_LONG(v);
515 if (scope != LOCAL) 549 if (scope != LOCAL)
516 continue; 550 continue;
517 if (!PySet_Contains(free, name)) 551 if (!PySet_Contains(free, name))
518 continue;
519 if (restricted != NULL &&
520 PyUnicode_CompareWithASCIIString(name, restricted))
521 continue; 552 continue;
522 /* Replace LOCAL with CELL for this name, and remove 553 /* Replace LOCAL with CELL for this name, and remove
523 from free. It is safe to replace the value of name 554 from free. It is safe to replace the value of name
524 in the dict, because it will not cause a resize. 555 in the dict, because it will not cause a resize.
525 */ 556 */
526 if (PyDict_SetItem(scopes, name, v_cell) < 0) 557 if (PyDict_SetItem(scopes, name, v_cell) < 0)
527 goto error; 558 goto error;
528 if (PySet_Discard(free, name) < 0) 559 if (PySet_Discard(free, name) < 0)
529 goto error; 560 goto error;
530 } 561 }
531 success = 1; 562 success = 1;
532 error: 563 error:
533 Py_DECREF(v_cell); 564 Py_DECREF(v_cell);
534 return success; 565 return success;
566 }
567
568 static int
569 drop_class_free(PySTEntryObject *ste, PyObject *free)
570 {
571 int res;
572 if (!GET_IDENTIFIER(__class__))
573 return 0;
574 res = PySet_Discard(free, __class__);
575 if (res < 0)
576 return 0;
577 if (res)
578 ste->ste_needs_class_closure = 1;
579 return 1;
535 } 580 }
536 581
537 /* Check for illegal statements in unoptimized namespaces */ 582 /* Check for illegal statements in unoptimized namespaces */
538 static int 583 static int
539 check_unoptimized(const PySTEntryObject* ste) { 584 check_unoptimized(const PySTEntryObject* ste) {
540 const char* trailer; 585 const char* trailer;
541 586
542 if (ste->ste_type != FunctionBlock || !ste->ste_unoptimized 587 if (ste->ste_type != FunctionBlock || !ste->ste_unoptimized
543 || !(ste->ste_free || ste->ste_child_free)) 588 || !(ste->ste_free || ste->ste_child_free))
544 return 1; 589 return 1;
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 /* Pass down known globals */ 803 /* Pass down known globals */
759 temp = PyNumber_InPlaceOr(newglobal, global); 804 temp = PyNumber_InPlaceOr(newglobal, global);
760 if (!temp) 805 if (!temp)
761 goto error; 806 goto error;
762 Py_DECREF(temp); 807 Py_DECREF(temp);
763 } 808 }
764 else { 809 else {
765 /* Special-case __class__ */ 810 /* Special-case __class__ */
766 if (!GET_IDENTIFIER(__class__)) 811 if (!GET_IDENTIFIER(__class__))
767 goto error; 812 goto error;
768 assert(PySet_Contains(local, __class__) == 1);
769 if (PySet_Add(newbound, __class__) < 0) 813 if (PySet_Add(newbound, __class__) < 0)
770 goto error; 814 goto error;
771 } 815 }
772 816
773 /* Recursively call analyze_child_block() on each child block. 817 /* Recursively call analyze_child_block() on each child block.
774 818
775 newbound, newglobal now contain the names visible in 819 newbound, newglobal now contain the names visible in
776 nested blocks. The free variables in the children will 820 nested blocks. The free variables in the children will
777 be collected in allfree. 821 be collected in allfree.
778 */ 822 */
(...skipping 12 matching lines...) Expand all
791 if (entry->ste_free || entry->ste_child_free) 835 if (entry->ste_free || entry->ste_child_free)
792 ste->ste_child_free = 1; 836 ste->ste_child_free = 1;
793 } 837 }
794 838
795 temp = PyNumber_InPlaceOr(newfree, allfree); 839 temp = PyNumber_InPlaceOr(newfree, allfree);
796 if (!temp) 840 if (!temp)
797 goto error; 841 goto error;
798 Py_DECREF(temp); 842 Py_DECREF(temp);
799 843
800 /* Check if any local variables must be converted to cell variables */ 844 /* Check if any local variables must be converted to cell variables */
801 if (ste->ste_type == FunctionBlock && !analyze_cells(scopes, newfree, 845 if (ste->ste_type == FunctionBlock && !analyze_cells(scopes, newfree))
802 NULL)) 846 goto error;
803 goto error; 847 else if (ste->ste_type == ClassBlock && !drop_class_free(ste, newfree))
804 else if (ste->ste_type == ClassBlock && !analyze_cells(scopes, newfree,
805 "__class__"))
806 goto error; 848 goto error;
807 /* Records the results of the analysis in the symbol table entry */ 849 /* Records the results of the analysis in the symbol table entry */
808 if (!update_symbols(ste->ste_symbols, scopes, bound, newfree, 850 if (!update_symbols(ste->ste_symbols, scopes, bound, newfree,
809 ste->ste_type == ClassBlock)) 851 ste->ste_type == ClassBlock))
810 goto error; 852 goto error;
811 if (!check_unoptimized(ste)) 853 if (!check_unoptimized(ste))
812 goto error; 854 goto error;
813 855
814 temp = PyNumber_InPlaceOr(free, newfree); 856 temp = PyNumber_InPlaceOr(free, newfree);
815 if (!temp) 857 if (!temp)
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 } 953 }
912 954
913 /* symtable_enter_block() gets a reference via ste_new. 955 /* symtable_enter_block() gets a reference via ste_new.
914 This reference is released when the block is exited, via the DECREF 956 This reference is released when the block is exited, via the DECREF
915 in symtable_exit_block(). 957 in symtable_exit_block().
916 */ 958 */
917 959
918 static int 960 static int
919 symtable_exit_block(struct symtable *st, void *ast) 961 symtable_exit_block(struct symtable *st, void *ast)
920 { 962 {
921 Py_ssize_t end; 963 Py_ssize_t size;
922 964
923 Py_CLEAR(st->st_cur); 965 st->st_cur = NULL;
924 end = PyList_GET_SIZE(st->st_stack) - 1; 966 size = PyList_GET_SIZE(st->st_stack);
925 if (end >= 0) { 967 if (size) {
926 st->st_cur = (PySTEntryObject *)PyList_GET_ITEM(st->st_stack, 968 if (PyList_SetSlice(st->st_stack, size - 1, size, NULL) < 0)
927 end);
928 if (st->st_cur == NULL)
929 return 0; 969 return 0;
930 Py_INCREF(st->st_cur); 970 if (--size)
931 if (PySequence_DelItem(st->st_stack, end) < 0) 971 st->st_cur = (PySTEntryObject *)PyList_GET_ITEM(st->st_stack, size - 1);
932 return 0;
933 } 972 }
934 return 1; 973 return 1;
935 } 974 }
936 975
937 static int 976 static int
938 symtable_enter_block(struct symtable *st, identifier name, _Py_block_ty block, 977 symtable_enter_block(struct symtable *st, identifier name, _Py_block_ty block,
939 void *ast, int lineno, int col_offset) 978 void *ast, int lineno, int col_offset)
940 { 979 {
941 PySTEntryObject *prev = NULL; 980 PySTEntryObject *prev = NULL, *ste;
942 981
943 if (st->st_cur) { 982 ste = ste_new(st, name, block, ast, lineno, col_offset);
944 prev = st->st_cur; 983 if (ste == NULL)
945 if (PyList_Append(st->st_stack, (PyObject *)st->st_cur) < 0) { 984 return 0;
946 return 0; 985 if (PyList_Append(st->st_stack, (PyObject *)ste) < 0) {
947 } 986 Py_DECREF(ste);
948 Py_DECREF(st->st_cur); 987 return 0;
949 } 988 }
950 st->st_cur = ste_new(st, name, block, ast, lineno, col_offset); 989 prev = st->st_cur;
951 if (st->st_cur == NULL) 990 /* The entry is owned by the stack. Borrow it for st_cur. */
952 return 0; 991 Py_DECREF(ste);
992 st->st_cur = ste;
953 if (block == ModuleBlock) 993 if (block == ModuleBlock)
954 st->st_global = st->st_cur->ste_symbols; 994 st->st_global = st->st_cur->ste_symbols;
955 if (prev) { 995 if (prev) {
956 if (PyList_Append(prev->ste_children, 996 if (PyList_Append(prev->ste_children, (PyObject *)ste) < 0) {
957 (PyObject *)st->st_cur) < 0) {
958 return 0; 997 return 0;
959 } 998 }
960 } 999 }
961 return 1; 1000 return 1;
962 } 1001 }
963 1002
964 static long 1003 static long
965 symtable_lookup(struct symtable *st, PyObject *name) 1004 symtable_lookup(struct symtable *st, PyObject *name)
966 { 1005 {
967 PyObject *o; 1006 PyObject *o;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 Py_DECREF(mangled); 1074 Py_DECREF(mangled);
1036 return 0; 1075 return 0;
1037 } 1076 }
1038 1077
1039 /* VISIT, VISIT_SEQ and VIST_SEQ_TAIL take an ASDL type as their second argument . 1078 /* VISIT, VISIT_SEQ and VIST_SEQ_TAIL take an ASDL type as their second argument .
1040 They use the ASDL name to synthesize the name of the C type and the visit 1079 They use the ASDL name to synthesize the name of the C type and the visit
1041 function. 1080 function.
1042 1081
1043 VISIT_SEQ_TAIL permits the start of an ASDL sequence to be skipped, which is 1082 VISIT_SEQ_TAIL permits the start of an ASDL sequence to be skipped, which is
1044 useful if the first node in the sequence requires special treatment. 1083 useful if the first node in the sequence requires special treatment.
1084
1085 VISIT_QUIT macro returns the specified value exiting from the function but
1086 first adjusts current recursion counter depth.
1045 */ 1087 */
1088
1089 #define VISIT_QUIT(ST, X) \
1090 return --(ST)->recursion_depth,(X)
1046 1091
1047 #define VISIT(ST, TYPE, V) \ 1092 #define VISIT(ST, TYPE, V) \
1048 if (!symtable_visit_ ## TYPE((ST), (V))) \ 1093 if (!symtable_visit_ ## TYPE((ST), (V))) \
1049 return 0; 1094 VISIT_QUIT((ST), 0);
1050
1051 #define VISIT_IN_BLOCK(ST, TYPE, V, S) \
1052 if (!symtable_visit_ ## TYPE((ST), (V))) { \
1053 symtable_exit_block((ST), (S)); \
1054 return 0; \
1055 }
1056 1095
1057 #define VISIT_SEQ(ST, TYPE, SEQ) { \ 1096 #define VISIT_SEQ(ST, TYPE, SEQ) { \
1058 int i; \ 1097 int i; \
1059 asdl_seq *seq = (SEQ); /* avoid variable capture */ \ 1098 asdl_seq *seq = (SEQ); /* avoid variable capture */ \
1060 for (i = 0; i < asdl_seq_LEN(seq); i++) { \ 1099 for (i = 0; i < asdl_seq_LEN(seq); i++) { \
1061 TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \ 1100 TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \
1062 if (!symtable_visit_ ## TYPE((ST), elt)) \ 1101 if (!symtable_visit_ ## TYPE((ST), elt)) \
1063 return 0; \ 1102 VISIT_QUIT((ST), 0); \
1064 } \
1065 }
1066
1067 #define VISIT_SEQ_IN_BLOCK(ST, TYPE, SEQ, S) { \
1068 int i; \
1069 asdl_seq *seq = (SEQ); /* avoid variable capture */ \
1070 for (i = 0; i < asdl_seq_LEN(seq); i++) { \
1071 TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \
1072 if (!symtable_visit_ ## TYPE((ST), elt)) { \
1073 symtable_exit_block((ST), (S)); \
1074 return 0; \
1075 } \
1076 } \ 1103 } \
1077 } 1104 }
1078 1105
1079 #define VISIT_SEQ_TAIL(ST, TYPE, SEQ, START) { \ 1106 #define VISIT_SEQ_TAIL(ST, TYPE, SEQ, START) { \
1080 int i; \ 1107 int i; \
1081 asdl_seq *seq = (SEQ); /* avoid variable capture */ \ 1108 asdl_seq *seq = (SEQ); /* avoid variable capture */ \
1082 for (i = (START); i < asdl_seq_LEN(seq); i++) { \ 1109 for (i = (START); i < asdl_seq_LEN(seq); i++) { \
1083 TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \ 1110 TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \
1084 if (!symtable_visit_ ## TYPE((ST), elt)) \ 1111 if (!symtable_visit_ ## TYPE((ST), elt)) \
1085 return 0; \ 1112 VISIT_QUIT((ST), 0); \
1086 } \
1087 }
1088
1089 #define VISIT_SEQ_TAIL_IN_BLOCK(ST, TYPE, SEQ, START, S) { \
1090 int i; \
1091 asdl_seq *seq = (SEQ); /* avoid variable capture */ \
1092 for (i = (START); i < asdl_seq_LEN(seq); i++) { \
1093 TYPE ## _ty elt = (TYPE ## _ty)asdl_seq_GET(seq, i); \
1094 if (!symtable_visit_ ## TYPE((ST), elt)) { \
1095 symtable_exit_block((ST), (S)); \
1096 return 0; \
1097 } \
1098 } \ 1113 } \
1099 } 1114 }
1100 1115
1101 #define VISIT_KWONLYDEFAULTS(ST, KW_DEFAULTS) { \ 1116 #define VISIT_KWONLYDEFAULTS(ST, KW_DEFAULTS) { \
1102 int i = 0; \ 1117 int i = 0; \
1103 asdl_seq *seq = (KW_DEFAULTS); /* avoid variable capture */ \ 1118 asdl_seq *seq = (KW_DEFAULTS); /* avoid variable capture */ \
1104 for (i = 0; i < asdl_seq_LEN(seq); i++) { \ 1119 for (i = 0; i < asdl_seq_LEN(seq); i++) { \
1105 expr_ty elt = (expr_ty)asdl_seq_GET(seq, i); \ 1120 expr_ty elt = (expr_ty)asdl_seq_GET(seq, i); \
1106 if (!elt) continue; /* can be NULL */ \ 1121 if (!elt) continue; /* can be NULL */ \
1107 if (!symtable_visit_expr((ST), elt)) \ 1122 if (!symtable_visit_expr((ST), elt)) \
1108 return 0; \ 1123 VISIT_QUIT((ST), 0); \
1109 } \ 1124 } \
1110 } 1125 }
1111 1126
1112 static int 1127 static int
1113 symtable_new_tmpname(struct symtable *st) 1128 symtable_new_tmpname(struct symtable *st)
1114 { 1129 {
1115 char tmpname[256]; 1130 char tmpname[256];
1116 identifier tmp; 1131 identifier tmp;
1117 1132
1118 PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]", 1133 PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]",
1119 ++st->st_cur->ste_tmpname); 1134 ++st->st_cur->ste_tmpname);
1120 tmp = PyUnicode_InternFromString(tmpname); 1135 tmp = PyUnicode_InternFromString(tmpname);
1121 if (!tmp) 1136 if (!tmp)
1122 return 0; 1137 return 0;
1123 if (!symtable_add_def(st, tmp, DEF_LOCAL)) 1138 if (!symtable_add_def(st, tmp, DEF_LOCAL))
1124 return 0; 1139 return 0;
1125 Py_DECREF(tmp); 1140 Py_DECREF(tmp);
1126 return 1; 1141 return 1;
1127 } 1142 }
1128 1143
1129 1144
1130 static int 1145 static int
1146 symtable_record_directive(struct symtable *st, identifier name, stmt_ty s)
1147 {
1148 PyObject *data;
1149 int res;
1150 if (!st->st_cur->ste_directives) {
1151 st->st_cur->ste_directives = PyList_New(0);
1152 if (!st->st_cur->ste_directives)
1153 return 0;
1154 }
1155 data = Py_BuildValue("(Oii)", name, s->lineno, s->col_offset);
1156 if (!data)
1157 return 0;
1158 res = PyList_Append(st->st_cur->ste_directives, data);
1159 Py_DECREF(data);
1160 return res == 0;
1161 }
1162
1163
1164 static int
1131 symtable_visit_stmt(struct symtable *st, stmt_ty s) 1165 symtable_visit_stmt(struct symtable *st, stmt_ty s)
1132 { 1166 {
1167 if (++st->recursion_depth > st->recursion_limit) {
1168 PyErr_SetString(PyExc_RuntimeError,
1169 "maximum recursion depth exceeded during compilation");
1170 VISIT_QUIT(st, 0);
1171 }
1133 switch (s->kind) { 1172 switch (s->kind) {
1134 case FunctionDef_kind: 1173 case FunctionDef_kind:
1135 if (!symtable_add_def(st, s->v.FunctionDef.name, DEF_LOCAL)) 1174 if (!symtable_add_def(st, s->v.FunctionDef.name, DEF_LOCAL))
1136 return 0; 1175 VISIT_QUIT(st, 0);
1137 if (s->v.FunctionDef.args->defaults) 1176 if (s->v.FunctionDef.args->defaults)
1138 VISIT_SEQ(st, expr, s->v.FunctionDef.args->defaults); 1177 VISIT_SEQ(st, expr, s->v.FunctionDef.args->defaults);
1139 if (s->v.FunctionDef.args->kw_defaults) 1178 if (s->v.FunctionDef.args->kw_defaults)
1140 VISIT_KWONLYDEFAULTS(st, 1179 VISIT_KWONLYDEFAULTS(st,
1141 s->v.FunctionDef.args->kw_defaults); 1180 s->v.FunctionDef.args->kw_defaults);
1142 if (!symtable_visit_annotations(st, s)) 1181 if (!symtable_visit_annotations(st, s))
1143 return 0; 1182 VISIT_QUIT(st, 0);
1144 if (s->v.FunctionDef.decorator_list) 1183 if (s->v.FunctionDef.decorator_list)
1145 VISIT_SEQ(st, expr, s->v.FunctionDef.decorator_list); 1184 VISIT_SEQ(st, expr, s->v.FunctionDef.decorator_list);
1146 if (!symtable_enter_block(st, s->v.FunctionDef.name, 1185 if (!symtable_enter_block(st, s->v.FunctionDef.name,
1147 FunctionBlock, (void *)s, s->lineno, 1186 FunctionBlock, (void *)s, s->lineno,
1148 s->col_offset)) 1187 s->col_offset))
1149 return 0; 1188 VISIT_QUIT(st, 0);
1150 VISIT_IN_BLOCK(st, arguments, s->v.FunctionDef.args, s); 1189 VISIT(st, arguments, s->v.FunctionDef.args);
1151 VISIT_SEQ_IN_BLOCK(st, stmt, s->v.FunctionDef.body, s); 1190 VISIT_SEQ(st, stmt, s->v.FunctionDef.body);
1152 if (!symtable_exit_block(st, s)) 1191 if (!symtable_exit_block(st, s))
1153 return 0; 1192 VISIT_QUIT(st, 0);
1154 break; 1193 break;
1155 case ClassDef_kind: { 1194 case ClassDef_kind: {
1156 PyObject *tmp; 1195 PyObject *tmp;
1157 if (!symtable_add_def(st, s->v.ClassDef.name, DEF_LOCAL)) 1196 if (!symtable_add_def(st, s->v.ClassDef.name, DEF_LOCAL))
1158 return 0; 1197 VISIT_QUIT(st, 0);
1159 VISIT_SEQ(st, expr, s->v.ClassDef.bases); 1198 VISIT_SEQ(st, expr, s->v.ClassDef.bases);
1160 VISIT_SEQ(st, keyword, s->v.ClassDef.keywords); 1199 VISIT_SEQ(st, keyword, s->v.ClassDef.keywords);
1161 if (s->v.ClassDef.starargs) 1200 if (s->v.ClassDef.starargs)
1162 VISIT(st, expr, s->v.ClassDef.starargs); 1201 VISIT(st, expr, s->v.ClassDef.starargs);
1163 if (s->v.ClassDef.kwargs) 1202 if (s->v.ClassDef.kwargs)
1164 VISIT(st, expr, s->v.ClassDef.kwargs); 1203 VISIT(st, expr, s->v.ClassDef.kwargs);
1165 if (s->v.ClassDef.decorator_list) 1204 if (s->v.ClassDef.decorator_list)
1166 VISIT_SEQ(st, expr, s->v.ClassDef.decorator_list); 1205 VISIT_SEQ(st, expr, s->v.ClassDef.decorator_list);
1167 if (!symtable_enter_block(st, s->v.ClassDef.name, ClassBlock, 1206 if (!symtable_enter_block(st, s->v.ClassDef.name, ClassBlock,
1168 (void *)s, s->lineno, s->col_offset)) 1207 (void *)s, s->lineno, s->col_offset))
1169 return 0; 1208 VISIT_QUIT(st, 0);
1170 if (!GET_IDENTIFIER(__class__) ||
1171 !symtable_add_def(st, __class__, DEF_LOCAL) ||
1172 !GET_IDENTIFIER(__locals__) ||
1173 !symtable_add_def(st, __locals__, DEF_PARAM)) {
1174 symtable_exit_block(st, s);
1175 return 0;
1176 }
1177 tmp = st->st_private; 1209 tmp = st->st_private;
1178 st->st_private = s->v.ClassDef.name; 1210 st->st_private = s->v.ClassDef.name;
1179 VISIT_SEQ_IN_BLOCK(st, stmt, s->v.ClassDef.body, s); 1211 VISIT_SEQ(st, stmt, s->v.ClassDef.body);
1180 st->st_private = tmp; 1212 st->st_private = tmp;
1181 if (!symtable_exit_block(st, s)) 1213 if (!symtable_exit_block(st, s))
1182 return 0; 1214 VISIT_QUIT(st, 0);
1183 break; 1215 break;
1184 } 1216 }
1185 case Return_kind: 1217 case Return_kind:
1186 if (s->v.Return.value) { 1218 if (s->v.Return.value) {
1187 VISIT(st, expr, s->v.Return.value); 1219 VISIT(st, expr, s->v.Return.value);
1188 st->st_cur->ste_returns_value = 1; 1220 st->st_cur->ste_returns_value = 1;
1189 if (st->st_cur->ste_generator) {
1190 PyErr_SetString(PyExc_SyntaxError,
1191 RETURN_VAL_IN_GENERATOR);
1192 PyErr_SyntaxLocationObject(st->st_filename,
1193 s->lineno,
1194 s->col_offset);
1195 return 0;
1196 }
1197 } 1221 }
1198 break; 1222 break;
1199 case Delete_kind: 1223 case Delete_kind:
1200 VISIT_SEQ(st, expr, s->v.Delete.targets); 1224 VISIT_SEQ(st, expr, s->v.Delete.targets);
1201 break; 1225 break;
1202 case Assign_kind: 1226 case Assign_kind:
1203 VISIT_SEQ(st, expr, s->v.Assign.targets); 1227 VISIT_SEQ(st, expr, s->v.Assign.targets);
1204 VISIT(st, expr, s->v.Assign.value); 1228 VISIT(st, expr, s->v.Assign.value);
1205 break; 1229 break;
1206 case AugAssign_kind: 1230 case AugAssign_kind:
(...skipping 21 matching lines...) Expand all
1228 VISIT_SEQ(st, stmt, s->v.If.orelse); 1252 VISIT_SEQ(st, stmt, s->v.If.orelse);
1229 break; 1253 break;
1230 case Raise_kind: 1254 case Raise_kind:
1231 if (s->v.Raise.exc) { 1255 if (s->v.Raise.exc) {
1232 VISIT(st, expr, s->v.Raise.exc); 1256 VISIT(st, expr, s->v.Raise.exc);
1233 if (s->v.Raise.cause) { 1257 if (s->v.Raise.cause) {
1234 VISIT(st, expr, s->v.Raise.cause); 1258 VISIT(st, expr, s->v.Raise.cause);
1235 } 1259 }
1236 } 1260 }
1237 break; 1261 break;
1238 case TryExcept_kind: 1262 case Try_kind:
1239 VISIT_SEQ(st, stmt, s->v.TryExcept.body); 1263 VISIT_SEQ(st, stmt, s->v.Try.body);
1240 VISIT_SEQ(st, stmt, s->v.TryExcept.orelse); 1264 VISIT_SEQ(st, stmt, s->v.Try.orelse);
1241 VISIT_SEQ(st, excepthandler, s->v.TryExcept.handlers); 1265 VISIT_SEQ(st, excepthandler, s->v.Try.handlers);
1242 break; 1266 VISIT_SEQ(st, stmt, s->v.Try.finalbody);
1243 case TryFinally_kind:
1244 VISIT_SEQ(st, stmt, s->v.TryFinally.body);
1245 VISIT_SEQ(st, stmt, s->v.TryFinally.finalbody);
1246 break; 1267 break;
1247 case Assert_kind: 1268 case Assert_kind:
1248 VISIT(st, expr, s->v.Assert.test); 1269 VISIT(st, expr, s->v.Assert.test);
1249 if (s->v.Assert.msg) 1270 if (s->v.Assert.msg)
1250 VISIT(st, expr, s->v.Assert.msg); 1271 VISIT(st, expr, s->v.Assert.msg);
1251 break; 1272 break;
1252 case Import_kind: 1273 case Import_kind:
1253 VISIT_SEQ(st, alias, s->v.Import.names); 1274 VISIT_SEQ(st, alias, s->v.Import.names);
1254 /* XXX Don't have the lineno available inside 1275 /* XXX Don't have the lineno available inside
1255 visit_alias */ 1276 visit_alias */
1256 if (st->st_cur->ste_unoptimized && !st->st_cur->ste_opt_lineno) { 1277 if (st->st_cur->ste_unoptimized && !st->st_cur->ste_opt_lineno) {
1257 st->st_cur->ste_opt_lineno = s->lineno; 1278 st->st_cur->ste_opt_lineno = s->lineno;
1258 st->st_cur->ste_opt_col_offset = s->col_offset; 1279 st->st_cur->ste_opt_col_offset = s->col_offset;
1259 } 1280 }
1260 break; 1281 break;
1261 case ImportFrom_kind: 1282 case ImportFrom_kind:
1262 VISIT_SEQ(st, alias, s->v.ImportFrom.names); 1283 VISIT_SEQ(st, alias, s->v.ImportFrom.names);
1263 /* XXX Don't have the lineno available inside 1284 /* XXX Don't have the lineno available inside
1264 visit_alias */ 1285 visit_alias */
1265 if (st->st_cur->ste_unoptimized && !st->st_cur->ste_opt_lineno) { 1286 if (st->st_cur->ste_unoptimized && !st->st_cur->ste_opt_lineno) {
1266 st->st_cur->ste_opt_lineno = s->lineno; 1287 st->st_cur->ste_opt_lineno = s->lineno;
1267 st->st_cur->ste_opt_col_offset = s->col_offset; 1288 st->st_cur->ste_opt_col_offset = s->col_offset;
1268 } 1289 }
1269 break; 1290 break;
1270 case Global_kind: { 1291 case Global_kind: {
1271 int i; 1292 int i;
1272 asdl_seq *seq = s->v.Global.names; 1293 asdl_seq *seq = s->v.Global.names;
1273 for (i = 0; i < asdl_seq_LEN(seq); i++) { 1294 for (i = 0; i < asdl_seq_LEN(seq); i++) {
1274 identifier name = (identifier)asdl_seq_GET(seq, i); 1295 identifier name = (identifier)asdl_seq_GET(seq, i);
1275 char *c_name = _PyUnicode_AsString(name);
1276 long cur = symtable_lookup(st, name); 1296 long cur = symtable_lookup(st, name);
1277 if (cur < 0) 1297 if (cur < 0)
1278 return 0; 1298 VISIT_QUIT(st, 0);
1279 if (cur & (DEF_LOCAL | USE)) { 1299 if (cur & (DEF_LOCAL | USE)) {
1280 char buf[256]; 1300 char buf[256];
1301 char *c_name = _PyUnicode_AsString(name);
1302 if (!c_name)
1303 return 0;
1281 if (cur & DEF_LOCAL) 1304 if (cur & DEF_LOCAL)
1282 PyOS_snprintf(buf, sizeof(buf), 1305 PyOS_snprintf(buf, sizeof(buf),
1283 GLOBAL_AFTER_ASSIGN, 1306 GLOBAL_AFTER_ASSIGN,
1284 c_name); 1307 c_name);
1285 else 1308 else
1286 PyOS_snprintf(buf, sizeof(buf), 1309 PyOS_snprintf(buf, sizeof(buf),
1287 GLOBAL_AFTER_USE, 1310 GLOBAL_AFTER_USE,
1288 c_name); 1311 c_name);
1289 if (!symtable_warn(st, buf, s->lineno)) 1312 if (!symtable_warn(st, buf, s->lineno))
1290 return 0; 1313 VISIT_QUIT(st, 0);
1291 } 1314 }
1292 if (!symtable_add_def(st, name, DEF_GLOBAL)) 1315 if (!symtable_add_def(st, name, DEF_GLOBAL))
1293 return 0; 1316 VISIT_QUIT(st, 0);
1317 if (!symtable_record_directive(st, name, s))
1318 VISIT_QUIT(st, 0);
1294 } 1319 }
1295 break; 1320 break;
1296 } 1321 }
1297 case Nonlocal_kind: { 1322 case Nonlocal_kind: {
1298 int i; 1323 int i;
1299 asdl_seq *seq = s->v.Nonlocal.names; 1324 asdl_seq *seq = s->v.Nonlocal.names;
1300 for (i = 0; i < asdl_seq_LEN(seq); i++) { 1325 for (i = 0; i < asdl_seq_LEN(seq); i++) {
1301 identifier name = (identifier)asdl_seq_GET(seq, i); 1326 identifier name = (identifier)asdl_seq_GET(seq, i);
1302 char *c_name = _PyUnicode_AsString(name);
1303 long cur = symtable_lookup(st, name); 1327 long cur = symtable_lookup(st, name);
1304 if (cur < 0) 1328 if (cur < 0)
1305 return 0; 1329 VISIT_QUIT(st, 0);
1306 if (cur & (DEF_LOCAL | USE)) { 1330 if (cur & (DEF_LOCAL | USE)) {
1307 char buf[256]; 1331 char buf[256];
1332 char *c_name = _PyUnicode_AsString(name);
1333 if (!c_name)
1334 return 0;
1308 if (cur & DEF_LOCAL) 1335 if (cur & DEF_LOCAL)
1309 PyOS_snprintf(buf, sizeof(buf), 1336 PyOS_snprintf(buf, sizeof(buf),
1310 NONLOCAL_AFTER_ASSIGN, 1337 NONLOCAL_AFTER_ASSIGN,
1311 c_name); 1338 c_name);
1312 else 1339 else
1313 PyOS_snprintf(buf, sizeof(buf), 1340 PyOS_snprintf(buf, sizeof(buf),
1314 NONLOCAL_AFTER_USE, 1341 NONLOCAL_AFTER_USE,
1315 c_name); 1342 c_name);
1316 if (!symtable_warn(st, buf, s->lineno)) 1343 if (!symtable_warn(st, buf, s->lineno))
1317 return 0; 1344 VISIT_QUIT(st, 0);
1318 } 1345 }
1319 if (!symtable_add_def(st, name, DEF_NONLOCAL)) 1346 if (!symtable_add_def(st, name, DEF_NONLOCAL))
1320 return 0; 1347 VISIT_QUIT(st, 0);
1348 if (!symtable_record_directive(st, name, s))
1349 VISIT_QUIT(st, 0);
1321 } 1350 }
1322 break; 1351 break;
1323 } 1352 }
1324 case Expr_kind: 1353 case Expr_kind:
1325 VISIT(st, expr, s->v.Expr.value); 1354 VISIT(st, expr, s->v.Expr.value);
1326 break; 1355 break;
1327 case Pass_kind: 1356 case Pass_kind:
1328 case Break_kind: 1357 case Break_kind:
1329 case Continue_kind: 1358 case Continue_kind:
1330 /* nothing to do here */ 1359 /* nothing to do here */
1331 break; 1360 break;
1332 case With_kind: 1361 case With_kind:
1333 VISIT(st, expr, s->v.With.context_expr); 1362 VISIT_SEQ(st, withitem, s->v.With.items);
1334 if (s->v.With.optional_vars) {
1335 VISIT(st, expr, s->v.With.optional_vars);
1336 }
1337 VISIT_SEQ(st, stmt, s->v.With.body); 1363 VISIT_SEQ(st, stmt, s->v.With.body);
1338 break; 1364 break;
1339 } 1365 }
1340 return 1; 1366 VISIT_QUIT(st, 1);
1341 } 1367 }
1342 1368
1343 static int 1369 static int
1344 symtable_visit_expr(struct symtable *st, expr_ty e) 1370 symtable_visit_expr(struct symtable *st, expr_ty e)
1345 { 1371 {
1372 if (++st->recursion_depth > st->recursion_limit) {
1373 PyErr_SetString(PyExc_RuntimeError,
1374 "maximum recursion depth exceeded during compilation");
1375 VISIT_QUIT(st, 0);
1376 }
1346 switch (e->kind) { 1377 switch (e->kind) {
1347 case BoolOp_kind: 1378 case BoolOp_kind:
1348 VISIT_SEQ(st, expr, e->v.BoolOp.values); 1379 VISIT_SEQ(st, expr, e->v.BoolOp.values);
1349 break; 1380 break;
1350 case BinOp_kind: 1381 case BinOp_kind:
1351 VISIT(st, expr, e->v.BinOp.left); 1382 VISIT(st, expr, e->v.BinOp.left);
1352 VISIT(st, expr, e->v.BinOp.right); 1383 VISIT(st, expr, e->v.BinOp.right);
1353 break; 1384 break;
1354 case UnaryOp_kind: 1385 case UnaryOp_kind:
1355 VISIT(st, expr, e->v.UnaryOp.operand); 1386 VISIT(st, expr, e->v.UnaryOp.operand);
1356 break; 1387 break;
1357 case Lambda_kind: { 1388 case Lambda_kind: {
1358 if (!GET_IDENTIFIER(lambda)) 1389 if (!GET_IDENTIFIER(lambda))
1359 return 0; 1390 VISIT_QUIT(st, 0);
1360 if (e->v.Lambda.args->defaults) 1391 if (e->v.Lambda.args->defaults)
1361 VISIT_SEQ(st, expr, e->v.Lambda.args->defaults); 1392 VISIT_SEQ(st, expr, e->v.Lambda.args->defaults);
1393 if (e->v.Lambda.args->kw_defaults)
1394 VISIT_KWONLYDEFAULTS(st,
1395 e->v.Lambda.args->kw_defaults);
1362 if (!symtable_enter_block(st, lambda, 1396 if (!symtable_enter_block(st, lambda,
1363 FunctionBlock, (void *)e, e->lineno, 1397 FunctionBlock, (void *)e, e->lineno,
1364 e->col_offset)) 1398 e->col_offset))
1365 return 0; 1399 VISIT_QUIT(st, 0);
1366 VISIT_IN_BLOCK(st, arguments, e->v.Lambda.args, (void*)e); 1400 VISIT(st, arguments, e->v.Lambda.args);
1367 VISIT_IN_BLOCK(st, expr, e->v.Lambda.body, (void*)e); 1401 VISIT(st, expr, e->v.Lambda.body);
1368 if (!symtable_exit_block(st, (void *)e)) 1402 if (!symtable_exit_block(st, (void *)e))
1369 return 0; 1403 VISIT_QUIT(st, 0);
1370 break; 1404 break;
1371 } 1405 }
1372 case IfExp_kind: 1406 case IfExp_kind:
1373 VISIT(st, expr, e->v.IfExp.test); 1407 VISIT(st, expr, e->v.IfExp.test);
1374 VISIT(st, expr, e->v.IfExp.body); 1408 VISIT(st, expr, e->v.IfExp.body);
1375 VISIT(st, expr, e->v.IfExp.orelse); 1409 VISIT(st, expr, e->v.IfExp.orelse);
1376 break; 1410 break;
1377 case Dict_kind: 1411 case Dict_kind:
1378 VISIT_SEQ(st, expr, e->v.Dict.keys); 1412 VISIT_SEQ(st, expr, e->v.Dict.keys);
1379 VISIT_SEQ(st, expr, e->v.Dict.values); 1413 VISIT_SEQ(st, expr, e->v.Dict.values);
1380 break; 1414 break;
1381 case Set_kind: 1415 case Set_kind:
1382 VISIT_SEQ(st, expr, e->v.Set.elts); 1416 VISIT_SEQ(st, expr, e->v.Set.elts);
1383 break; 1417 break;
1384 case GeneratorExp_kind: 1418 case GeneratorExp_kind:
1385 if (!symtable_visit_genexp(st, e)) 1419 if (!symtable_visit_genexp(st, e))
1386 return 0; 1420 VISIT_QUIT(st, 0);
1387 break; 1421 break;
1388 case ListComp_kind: 1422 case ListComp_kind:
1389 if (!symtable_visit_listcomp(st, e)) 1423 if (!symtable_visit_listcomp(st, e))
1390 return 0; 1424 VISIT_QUIT(st, 0);
1391 break; 1425 break;
1392 case SetComp_kind: 1426 case SetComp_kind:
1393 if (!symtable_visit_setcomp(st, e)) 1427 if (!symtable_visit_setcomp(st, e))
1394 return 0; 1428 VISIT_QUIT(st, 0);
1395 break; 1429 break;
1396 case DictComp_kind: 1430 case DictComp_kind:
1397 if (!symtable_visit_dictcomp(st, e)) 1431 if (!symtable_visit_dictcomp(st, e))
1398 return 0; 1432 VISIT_QUIT(st, 0);
1399 break; 1433 break;
1400 case Yield_kind: 1434 case Yield_kind:
1401 if (e->v.Yield.value) 1435 if (e->v.Yield.value)
1402 VISIT(st, expr, e->v.Yield.value); 1436 VISIT(st, expr, e->v.Yield.value);
1403 st->st_cur->ste_generator = 1; 1437 st->st_cur->ste_generator = 1;
1404 if (st->st_cur->ste_returns_value) { 1438 break;
1405 PyErr_SetString(PyExc_SyntaxError, 1439 case YieldFrom_kind:
1406 RETURN_VAL_IN_GENERATOR); 1440 VISIT(st, expr, e->v.YieldFrom.value);
1407 PyErr_SyntaxLocationObject(st->st_filename, 1441 st->st_cur->ste_generator = 1;
1408 e->lineno, e->col_offset);
1409 return 0;
1410 }
1411 break; 1442 break;
1412 case Compare_kind: 1443 case Compare_kind:
1413 VISIT(st, expr, e->v.Compare.left); 1444 VISIT(st, expr, e->v.Compare.left);
1414 VISIT_SEQ(st, expr, e->v.Compare.comparators); 1445 VISIT_SEQ(st, expr, e->v.Compare.comparators);
1415 break; 1446 break;
1416 case Call_kind: 1447 case Call_kind:
1417 VISIT(st, expr, e->v.Call.func); 1448 VISIT(st, expr, e->v.Call.func);
1418 VISIT_SEQ(st, expr, e->v.Call.args); 1449 VISIT_SEQ(st, expr, e->v.Call.args);
1419 VISIT_SEQ(st, keyword, e->v.Call.keywords); 1450 VISIT_SEQ(st, keyword, e->v.Call.keywords);
1420 if (e->v.Call.starargs) 1451 if (e->v.Call.starargs)
1421 VISIT(st, expr, e->v.Call.starargs); 1452 VISIT(st, expr, e->v.Call.starargs);
1422 if (e->v.Call.kwargs) 1453 if (e->v.Call.kwargs)
1423 VISIT(st, expr, e->v.Call.kwargs); 1454 VISIT(st, expr, e->v.Call.kwargs);
1424 break; 1455 break;
1425 case Num_kind: 1456 case Num_kind:
1426 case Str_kind: 1457 case Str_kind:
1427 case Bytes_kind: 1458 case Bytes_kind:
1428 case Ellipsis_kind: 1459 case Ellipsis_kind:
1460 case NameConstant_kind:
1429 /* Nothing to do here. */ 1461 /* Nothing to do here. */
1430 break; 1462 break;
1431 /* The following exprs can be assignment targets. */ 1463 /* The following exprs can be assignment targets. */
1432 case Attribute_kind: 1464 case Attribute_kind:
1433 VISIT(st, expr, e->v.Attribute.value); 1465 VISIT(st, expr, e->v.Attribute.value);
1434 break; 1466 break;
1435 case Subscript_kind: 1467 case Subscript_kind:
1436 VISIT(st, expr, e->v.Subscript.value); 1468 VISIT(st, expr, e->v.Subscript.value);
1437 VISIT(st, slice, e->v.Subscript.slice); 1469 VISIT(st, slice, e->v.Subscript.slice);
1438 break; 1470 break;
1439 case Starred_kind: 1471 case Starred_kind:
1440 VISIT(st, expr, e->v.Starred.value); 1472 VISIT(st, expr, e->v.Starred.value);
1441 break; 1473 break;
1442 case Name_kind: 1474 case Name_kind:
1443 if (!symtable_add_def(st, e->v.Name.id, 1475 if (!symtable_add_def(st, e->v.Name.id,
1444 e->v.Name.ctx == Load ? USE : DEF_LOCAL)) 1476 e->v.Name.ctx == Load ? USE : DEF_LOCAL))
1445 return 0; 1477 VISIT_QUIT(st, 0);
1446 /* Special-case super: it counts as a use of __class__ */ 1478 /* Special-case super: it counts as a use of __class__ */
1447 if (e->v.Name.ctx == Load && 1479 if (e->v.Name.ctx == Load &&
1448 st->st_cur->ste_type == FunctionBlock && 1480 st->st_cur->ste_type == FunctionBlock &&
1449 !PyUnicode_CompareWithASCIIString(e->v.Name.id, "super")) { 1481 !PyUnicode_CompareWithASCIIString(e->v.Name.id, "super")) {
1450 if (!GET_IDENTIFIER(__class__) || 1482 if (!GET_IDENTIFIER(__class__) ||
1451 !symtable_add_def(st, __class__, USE)) 1483 !symtable_add_def(st, __class__, USE))
1452 return 0; 1484 VISIT_QUIT(st, 0);
1453 } 1485 }
1454 break; 1486 break;
1455 /* child nodes of List and Tuple will have expr_context set */ 1487 /* child nodes of List and Tuple will have expr_context set */
1456 case List_kind: 1488 case List_kind:
1457 VISIT_SEQ(st, expr, e->v.List.elts); 1489 VISIT_SEQ(st, expr, e->v.List.elts);
1458 break; 1490 break;
1459 case Tuple_kind: 1491 case Tuple_kind:
1460 VISIT_SEQ(st, expr, e->v.Tuple.elts); 1492 VISIT_SEQ(st, expr, e->v.Tuple.elts);
1461 break; 1493 break;
1462 } 1494 }
1463 return 1; 1495 VISIT_QUIT(st, 1);
1464 } 1496 }
1465 1497
1466 static int 1498 static int
1467 symtable_implicit_arg(struct symtable *st, int pos) 1499 symtable_implicit_arg(struct symtable *st, int pos)
1468 { 1500 {
1469 PyObject *id = PyUnicode_FromFormat(".%d", pos); 1501 PyObject *id = PyUnicode_FromFormat(".%d", pos);
1470 if (id == NULL) 1502 if (id == NULL)
1471 return 0; 1503 return 0;
1472 if (!symtable_add_def(st, id, DEF_PARAM)) { 1504 if (!symtable_add_def(st, id, DEF_PARAM)) {
1473 Py_DECREF(id); 1505 Py_DECREF(id);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1511 return 1; 1543 return 1;
1512 } 1544 }
1513 1545
1514 static int 1546 static int
1515 symtable_visit_annotations(struct symtable *st, stmt_ty s) 1547 symtable_visit_annotations(struct symtable *st, stmt_ty s)
1516 { 1548 {
1517 arguments_ty a = s->v.FunctionDef.args; 1549 arguments_ty a = s->v.FunctionDef.args;
1518 1550
1519 if (a->args && !symtable_visit_argannotations(st, a->args)) 1551 if (a->args && !symtable_visit_argannotations(st, a->args))
1520 return 0; 1552 return 0;
1521 if (a->varargannotation) 1553 if (a->vararg && a->vararg->annotation)
1522 VISIT(st, expr, a->varargannotation); 1554 VISIT(st, expr, a->vararg->annotation);
1523 if (a->kwargannotation) 1555 if (a->kwarg && a->kwarg->annotation)
1524 VISIT(st, expr, a->kwargannotation); 1556 VISIT(st, expr, a->kwarg->annotation);
1525 if (a->kwonlyargs && !symtable_visit_argannotations(st, a->kwonlyargs)) 1557 if (a->kwonlyargs && !symtable_visit_argannotations(st, a->kwonlyargs))
1526 return 0; 1558 return 0;
1527 if (s->v.FunctionDef.returns) 1559 if (s->v.FunctionDef.returns)
1528 VISIT(st, expr, s->v.FunctionDef.returns); 1560 VISIT(st, expr, s->v.FunctionDef.returns);
1529 return 1; 1561 return 1;
1530 } 1562 }
1531 1563
1532 static int 1564 static int
1533 symtable_visit_arguments(struct symtable *st, arguments_ty a) 1565 symtable_visit_arguments(struct symtable *st, arguments_ty a)
1534 { 1566 {
1535 /* skip default arguments inside function block 1567 /* skip default arguments inside function block
1536 XXX should ast be different? 1568 XXX should ast be different?
1537 */ 1569 */
1538 if (a->args && !symtable_visit_params(st, a->args)) 1570 if (a->args && !symtable_visit_params(st, a->args))
1539 return 0; 1571 return 0;
1540 if (a->kwonlyargs && !symtable_visit_params(st, a->kwonlyargs)) 1572 if (a->kwonlyargs && !symtable_visit_params(st, a->kwonlyargs))
1541 return 0; 1573 return 0;
1542 if (a->vararg) { 1574 if (a->vararg) {
1543 if (!symtable_add_def(st, a->vararg, DEF_PARAM)) 1575 if (!symtable_add_def(st, a->vararg->arg, DEF_PARAM))
1544 return 0; 1576 return 0;
1545 st->st_cur->ste_varargs = 1; 1577 st->st_cur->ste_varargs = 1;
1546 } 1578 }
1547 if (a->kwarg) { 1579 if (a->kwarg) {
1548 if (!symtable_add_def(st, a->kwarg, DEF_PARAM)) 1580 if (!symtable_add_def(st, a->kwarg->arg, DEF_PARAM))
1549 return 0; 1581 return 0;
1550 st->st_cur->ste_varkeywords = 1; 1582 st->st_cur->ste_varkeywords = 1;
1551 } 1583 }
1552 return 1; 1584 return 1;
1553 } 1585 }
1554 1586
1555 1587
1556 static int 1588 static int
1557 symtable_visit_excepthandler(struct symtable *st, excepthandler_ty eh) 1589 symtable_visit_excepthandler(struct symtable *st, excepthandler_ty eh)
1558 { 1590 {
1559 if (eh->v.ExceptHandler.type) 1591 if (eh->v.ExceptHandler.type)
1560 VISIT(st, expr, eh->v.ExceptHandler.type); 1592 VISIT(st, expr, eh->v.ExceptHandler.type);
1561 if (eh->v.ExceptHandler.name) 1593 if (eh->v.ExceptHandler.name)
1562 if (!symtable_add_def(st, eh->v.ExceptHandler.name, DEF_LOCAL)) 1594 if (!symtable_add_def(st, eh->v.ExceptHandler.name, DEF_LOCAL))
1563 return 0; 1595 return 0;
1564 VISIT_SEQ(st, stmt, eh->v.ExceptHandler.body); 1596 VISIT_SEQ(st, stmt, eh->v.ExceptHandler.body);
1565 return 1; 1597 return 1;
1566 } 1598 }
1567 1599
1600 static int
1601 symtable_visit_withitem(struct symtable *st, withitem_ty item)
1602 {
1603 VISIT(st, expr, item->context_expr);
1604 if (item->optional_vars) {
1605 VISIT(st, expr, item->optional_vars);
1606 }
1607 return 1;
1608 }
1609
1568 1610
1569 static int 1611 static int
1570 symtable_visit_alias(struct symtable *st, alias_ty a) 1612 symtable_visit_alias(struct symtable *st, alias_ty a)
1571 { 1613 {
1572 /* Compute store_name, the name actually bound by the import 1614 /* Compute store_name, the name actually bound by the import
1573 operation. It is different than a->name when a->name is a 1615 operation. It is different than a->name when a->name is a
1574 dotted package name (e.g. spam.eggs) 1616 dotted package name (e.g. spam.eggs)
1575 */ 1617 */
1576 PyObject *store_name; 1618 PyObject *store_name;
1577 PyObject *name = (a->asname == NULL) ? a->name : a->asname; 1619 PyObject *name = (a->asname == NULL) ? a->name : a->asname;
1578 const Py_UNICODE *base = PyUnicode_AS_UNICODE(name); 1620 Py_ssize_t dot = PyUnicode_FindChar(name, '.', 0,
1579 Py_UNICODE *dot = Py_UNICODE_strchr(base, '.'); 1621 PyUnicode_GET_LENGTH(name), 1);
1580 if (dot) { 1622 if (dot != -1) {
1581 store_name = PyUnicode_FromUnicode(base, dot - base); 1623 store_name = PyUnicode_Substring(name, 0, dot);
1582 if (!store_name) 1624 if (!store_name)
1583 return 0; 1625 return 0;
1584 } 1626 }
1585 else { 1627 else {
1586 store_name = name; 1628 store_name = name;
1587 Py_INCREF(store_name); 1629 Py_INCREF(store_name);
1588 } 1630 }
1589 if (PyUnicode_CompareWithASCIIString(name, "*")) { 1631 if (PyUnicode_CompareWithASCIIString(name, "*")) {
1590 int r = symtable_add_def(st, store_name, DEF_IMPORT); 1632 int r = symtable_add_def(st, store_name, DEF_IMPORT);
1591 Py_DECREF(store_name); 1633 Py_DECREF(store_name);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1668 /* Outermost iter is received as an argument */ 1710 /* Outermost iter is received as an argument */
1669 if (!symtable_implicit_arg(st, 0)) { 1711 if (!symtable_implicit_arg(st, 0)) {
1670 symtable_exit_block(st, (void *)e); 1712 symtable_exit_block(st, (void *)e);
1671 return 0; 1713 return 0;
1672 } 1714 }
1673 /* Allocate temporary name if needed */ 1715 /* Allocate temporary name if needed */
1674 if (needs_tmp && !symtable_new_tmpname(st)) { 1716 if (needs_tmp && !symtable_new_tmpname(st)) {
1675 symtable_exit_block(st, (void *)e); 1717 symtable_exit_block(st, (void *)e);
1676 return 0; 1718 return 0;
1677 } 1719 }
1678 VISIT_IN_BLOCK(st, expr, outermost->target, (void*)e); 1720 VISIT(st, expr, outermost->target);
1679 VISIT_SEQ_IN_BLOCK(st, expr, outermost->ifs, (void*)e); 1721 VISIT_SEQ(st, expr, outermost->ifs);
1680 VISIT_SEQ_TAIL_IN_BLOCK(st, comprehension, 1722 VISIT_SEQ_TAIL(st, comprehension, generators, 1);
1681 generators, 1, (void*)e);
1682 if (value) 1723 if (value)
1683 VISIT_IN_BLOCK(st, expr, value, (void*)e); 1724 VISIT(st, expr, value);
1684 VISIT_IN_BLOCK(st, expr, elt, (void*)e); 1725 VISIT(st, expr, elt);
1685 return symtable_exit_block(st, (void *)e); 1726 return symtable_exit_block(st, (void *)e);
1686 } 1727 }
1687 1728
1688 static int 1729 static int
1689 symtable_visit_genexp(struct symtable *st, expr_ty e) 1730 symtable_visit_genexp(struct symtable *st, expr_ty e)
1690 { 1731 {
1691 return symtable_handle_comprehension(st, e, GET_IDENTIFIER(genexpr), 1732 return symtable_handle_comprehension(st, e, GET_IDENTIFIER(genexpr),
1692 e->v.GeneratorExp.generators, 1733 e->v.GeneratorExp.generators,
1693 e->v.GeneratorExp.elt, NULL); 1734 e->v.GeneratorExp.elt, NULL);
1694 } 1735 }
(...skipping 15 matching lines...) Expand all
1710 } 1751 }
1711 1752
1712 static int 1753 static int
1713 symtable_visit_dictcomp(struct symtable *st, expr_ty e) 1754 symtable_visit_dictcomp(struct symtable *st, expr_ty e)
1714 { 1755 {
1715 return symtable_handle_comprehension(st, e, GET_IDENTIFIER(dictcomp), 1756 return symtable_handle_comprehension(st, e, GET_IDENTIFIER(dictcomp),
1716 e->v.DictComp.generators, 1757 e->v.DictComp.generators,
1717 e->v.DictComp.key, 1758 e->v.DictComp.key,
1718 e->v.DictComp.value); 1759 e->v.DictComp.value);
1719 } 1760 }
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+