summaryrefslogtreecommitdiffstats
path: root/Include/symtable.h
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2007-02-27 06:50:52 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2007-02-27 06:50:52 (GMT)
commit81e9502df69394821416309c7c4b5357af51f4d5 (patch)
treead38831cbebfb32890c0c57cb8b36f653300c69f /Include/symtable.h
parent8b41c3dc28a16da97af50cc5f7b884db2cea7b0c (diff)
downloadcpython-81e9502df69394821416309c7c4b5357af51f4d5.zip
cpython-81e9502df69394821416309c7c4b5357af51f4d5.tar.gz
cpython-81e9502df69394821416309c7c4b5357af51f4d5.tar.bz2
Provisional implementation of PEP 3104.
Add nonlocal_stmt to Grammar and Nonlocal node to AST. They both parallel the definitions for globals. The symbol table treats variables declared as nonlocal just like variables that are free implicitly. This change is missing the language spec changes, but makes some decisions about what the spec should say via the unittests. The PEP is silent on a number of decisions, so we should review those before claiming that nonlocal is complete. Thomas Wouters made the grammer and ast changes. Jeremy Hylton added the symbol table changes and the tests. Pete Shinners and Neal Norwitz helped review the code.
Diffstat (limited to 'Include/symtable.h')
-rw-r--r--Include/symtable.h21
1 files changed, 11 insertions, 10 deletions
diff --git a/Include/symtable.h b/Include/symtable.h
index f40bfa4..5f50105 100644
--- a/Include/symtable.h
+++ b/Include/symtable.h
@@ -64,23 +64,24 @@ PyAPI_FUNC(void) PySymtable_Free(struct symtable *);
#define DEF_GLOBAL 1 /* global stmt */
#define DEF_LOCAL 2 /* assignment in code block */
#define DEF_PARAM 2<<1 /* formal parameter */
-#define USE 2<<2 /* name is used */
-#define DEF_STAR 2<<3 /* parameter is star arg */
-#define DEF_DOUBLESTAR 2<<4 /* parameter is star-star arg */
-#define DEF_INTUPLE 2<<5 /* name defined in tuple in parameters */
-#define DEF_FREE 2<<6 /* name used but not defined in nested block */
-#define DEF_FREE_GLOBAL 2<<7 /* free variable is actually implicit global */
-#define DEF_FREE_CLASS 2<<8 /* free variable from class's method */
-#define DEF_IMPORT 2<<9 /* assignment occurred via import */
+#define DEF_NONLOCAL 2<<2 /* nonlocal stmt */
+#define USE 2<<3 /* name is used */
+#define DEF_STAR 2<<4 /* parameter is star arg */
+#define DEF_DOUBLESTAR 2<<5 /* parameter is star-star arg */
+#define DEF_INTUPLE 2<<6 /* name defined in tuple in parameters */
+#define DEF_FREE 2<<7 /* name used but not defined in nested block */
+#define DEF_FREE_GLOBAL 2<<8 /* free variable is actually implicit global */
+#define DEF_FREE_CLASS 2<<9 /* free variable from class's method */
+#define DEF_IMPORT 2<<10 /* assignment occurred via import */
#define DEF_BOUND (DEF_LOCAL | DEF_PARAM | DEF_IMPORT)
/* GLOBAL_EXPLICIT and GLOBAL_IMPLICIT are used internally by the symbol
table. GLOBAL is returned from PyST_GetScope() for either of them.
- It is stored in ste_symbols at bits 12-14.
+ It is stored in ste_symbols at bits 12-15.
*/
#define SCOPE_OFF 11
-#define SCOPE_MASK 7
+#define SCOPE_MASK (DEF_GLOBAL | DEF_LOCAL | DEF_PARAM | DEF_NONLOCAL)
#define LOCAL 1
#define GLOBAL_EXPLICIT 2