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

Delta Between Two Patch Sets: Python/symtable.c

Issue 11682: PEP 380 reference implementation for 3.3
Left Patch Set: Created 7 years, 10 months ago
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« Objects/exceptions.c ('K') | « Python/Python-ast.c ('k') | no next file » | 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
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 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 VISIT(st, expr, e->v.BinOp.right); 1281 VISIT(st, expr, e->v.BinOp.right);
1286 break; 1282 break;
1287 case UnaryOp_kind: 1283 case UnaryOp_kind:
1288 VISIT(st, expr, e->v.UnaryOp.operand); 1284 VISIT(st, expr, e->v.UnaryOp.operand);
1289 break; 1285 break;
1290 case Lambda_kind: { 1286 case Lambda_kind: {
1291 if (!GET_IDENTIFIER(lambda)) 1287 if (!GET_IDENTIFIER(lambda))
1292 return 0; 1288 return 0;
1293 if (e->v.Lambda.args->defaults) 1289 if (e->v.Lambda.args->defaults)
1294 VISIT_SEQ(st, expr, e->v.Lambda.args->defaults); 1290 VISIT_SEQ(st, expr, e->v.Lambda.args->defaults);
1291 if (e->v.Lambda.args->kw_defaults)
1292 VISIT_KWONLYDEFAULTS(st,
1293 e->v.Lambda.args->kw_defaults);
1295 if (!symtable_enter_block(st, lambda, 1294 if (!symtable_enter_block(st, lambda,
1296 FunctionBlock, (void *)e, e->lineno, 1295 FunctionBlock, (void *)e, e->lineno,
1297 e->col_offset)) 1296 e->col_offset))
1298 return 0; 1297 return 0;
1299 VISIT(st, arguments, e->v.Lambda.args); 1298 VISIT(st, arguments, e->v.Lambda.args);
1300 VISIT(st, expr, e->v.Lambda.body); 1299 VISIT(st, expr, e->v.Lambda.body);
1301 if (!symtable_exit_block(st, (void *)e)) 1300 if (!symtable_exit_block(st, (void *)e))
1302 return 0; 1301 return 0;
1303 break; 1302 break;
1304 } 1303 }
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 1502
1504 static int 1503 static int
1505 symtable_visit_alias(struct symtable *st, alias_ty a) 1504 symtable_visit_alias(struct symtable *st, alias_ty a)
1506 { 1505 {
1507 /* Compute store_name, the name actually bound by the import 1506 /* Compute store_name, the name actually bound by the import
1508 operation. It is different than a->name when a->name is a 1507 operation. It is different than a->name when a->name is a
1509 dotted package name (e.g. spam.eggs) 1508 dotted package name (e.g. spam.eggs)
1510 */ 1509 */
1511 PyObject *store_name; 1510 PyObject *store_name;
1512 PyObject *name = (a->asname == NULL) ? a->name : a->asname; 1511 PyObject *name = (a->asname == NULL) ? a->name : a->asname;
1513 const Py_UNICODE *base = PyUnicode_AS_UNICODE(name); 1512 Py_ssize_t dot = PyUnicode_FindChar(name, '.', 0,
1514 Py_UNICODE *dot = Py_UNICODE_strchr(base, '.'); 1513 PyUnicode_GET_LENGTH(name), 1);
1515 if (dot) { 1514 if (dot != -1) {
1516 store_name = PyUnicode_FromUnicode(base, dot - base); 1515 store_name = PyUnicode_Substring(name, 0, dot);
1517 if (!store_name) 1516 if (!store_name)
1518 return 0; 1517 return 0;
1519 } 1518 }
1520 else { 1519 else {
1521 store_name = name; 1520 store_name = name;
1522 Py_INCREF(store_name); 1521 Py_INCREF(store_name);
1523 } 1522 }
1524 if (PyUnicode_CompareWithASCIIString(name, "*")) { 1523 if (PyUnicode_CompareWithASCIIString(name, "*")) {
1525 int r = symtable_add_def(st, store_name, DEF_IMPORT); 1524 int r = symtable_add_def(st, store_name, DEF_IMPORT);
1526 Py_DECREF(store_name); 1525 Py_DECREF(store_name);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1644 } 1643 }
1645 1644
1646 static int 1645 static int
1647 symtable_visit_dictcomp(struct symtable *st, expr_ty e) 1646 symtable_visit_dictcomp(struct symtable *st, expr_ty e)
1648 { 1647 {
1649 return symtable_handle_comprehension(st, e, GET_IDENTIFIER(dictcomp), 1648 return symtable_handle_comprehension(st, e, GET_IDENTIFIER(dictcomp),
1650 e->v.DictComp.generators, 1649 e->v.DictComp.generators,
1651 e->v.DictComp.key, 1650 e->v.DictComp.key,
1652 e->v.DictComp.value); 1651 e->v.DictComp.value);
1653 } 1652 }
LEFTRIGHT

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