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

Side by Side Diff: Python/symtable.c

Issue 11682: PEP 380 reference implementation for 3.3
Patch Set: Created 7 years, 4 months 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:
View unified diff | Download patch
« Objects/exceptions.c ('K') | « Python/Python-ast.c ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
22 #define RETURN_VAL_IN_GENERATOR \
23 "'return' with argument inside generator"
24
25 21
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;
32 28
33 k = PyLong_FromVoidPtr(key); 29 k = PyLong_FromVoidPtr(key);
34 if (k == NULL) 30 if (k == NULL)
(...skipping 1091 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 VISIT_SEQ(st, stmt, s->v.ClassDef.body); 1122 VISIT_SEQ(st, stmt, s->v.ClassDef.body);
1127 st->st_private = tmp; 1123 st->st_private = tmp;
1128 if (!symtable_exit_block(st, s)) 1124 if (!symtable_exit_block(st, s))
1129 return 0; 1125 return 0;
1130 break; 1126 break;
1131 } 1127 }
1132 case Return_kind: 1128 case Return_kind:
1133 if (s->v.Return.value) { 1129 if (s->v.Return.value) {
1134 VISIT(st, expr, s->v.Return.value); 1130 VISIT(st, expr, s->v.Return.value);
1135 st->st_cur->ste_returns_value = 1; 1131 st->st_cur->ste_returns_value = 1;
1136 if (st->st_cur->ste_generator) {
1137 PyErr_SetString(PyExc_SyntaxError,
1138 RETURN_VAL_IN_GENERATOR);
1139 PyErr_SyntaxLocationEx(st->st_filename,
1140 s->lineno,
1141 s->col_offset);
1142 return 0;
1143 }
1144 } 1132 }
1145 break; 1133 break;
1146 case Delete_kind: 1134 case Delete_kind:
1147 VISIT_SEQ(st, expr, s->v.Delete.targets); 1135 VISIT_SEQ(st, expr, s->v.Delete.targets);
1148 break; 1136 break;
1149 case Assign_kind: 1137 case Assign_kind:
1150 VISIT_SEQ(st, expr, s->v.Assign.targets); 1138 VISIT_SEQ(st, expr, s->v.Assign.targets);
1151 VISIT(st, expr, s->v.Assign.value); 1139 VISIT(st, expr, s->v.Assign.value);
1152 break; 1140 break;
1153 case AugAssign_kind: 1141 case AugAssign_kind:
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 return 0; 1326 return 0;
1339 break; 1327 break;
1340 case DictComp_kind: 1328 case DictComp_kind:
1341 if (!symtable_visit_dictcomp(st, e)) 1329 if (!symtable_visit_dictcomp(st, e))
1342 return 0; 1330 return 0;
1343 break; 1331 break;
1344 case Yield_kind: 1332 case Yield_kind:
1345 if (e->v.Yield.value) 1333 if (e->v.Yield.value)
1346 VISIT(st, expr, e->v.Yield.value); 1334 VISIT(st, expr, e->v.Yield.value);
1347 st->st_cur->ste_generator = 1; 1335 st->st_cur->ste_generator = 1;
1348 if (st->st_cur->ste_returns_value) {
1349 PyErr_SetString(PyExc_SyntaxError,
1350 RETURN_VAL_IN_GENERATOR);
1351 PyErr_SyntaxLocationEx(st->st_filename,
1352 e->lineno, e->col_offset);
1353 return 0;
1354 }
1355 break; 1336 break;
1356 case Compare_kind: 1337 case Compare_kind:
1357 VISIT(st, expr, e->v.Compare.left); 1338 VISIT(st, expr, e->v.Compare.left);
1358 VISIT_SEQ(st, expr, e->v.Compare.comparators); 1339 VISIT_SEQ(st, expr, e->v.Compare.comparators);
1359 break; 1340 break;
1360 case Call_kind: 1341 case Call_kind:
1361 VISIT(st, expr, e->v.Call.func); 1342 VISIT(st, expr, e->v.Call.func);
1362 VISIT_SEQ(st, expr, e->v.Call.args); 1343 VISIT_SEQ(st, expr, e->v.Call.args);
1363 VISIT_SEQ(st, keyword, e->v.Call.keywords); 1344 VISIT_SEQ(st, keyword, e->v.Call.keywords);
1364 if (e->v.Call.starargs) 1345 if (e->v.Call.starargs)
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1662 } 1643 }
1663 1644
1664 static int 1645 static int
1665 symtable_visit_dictcomp(struct symtable *st, expr_ty e) 1646 symtable_visit_dictcomp(struct symtable *st, expr_ty e)
1666 { 1647 {
1667 return symtable_handle_comprehension(st, e, GET_IDENTIFIER(dictcomp), 1648 return symtable_handle_comprehension(st, e, GET_IDENTIFIER(dictcomp),
1668 e->v.DictComp.generators, 1649 e->v.DictComp.generators,
1669 e->v.DictComp.key, 1650 e->v.DictComp.key,
1670 e->v.DictComp.value); 1651 e->v.DictComp.value);
1671 } 1652 }
OLDNEW
« Objects/exceptions.c ('K') | « Python/Python-ast.c ('k') | no next file » | no next file with comments »

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