Mercurial > cpython-lru_cache-weakref
annotate Include/symtable.h @ 27998:e27f58a50737 legacy-trunk
SF bug #690377: Dud footnote reference in distutils docs
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Fri, 21 Feb 2003 02:47:09 +0000 |
| parents | cc05c2c8660e |
| children | cd1c826c98a2 |
| rev | line source |
|---|---|
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
1 #ifndef Py_SYMTABLE_H |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
2 #define Py_SYMTABLE_H |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
3 #ifdef __cplusplus |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
4 extern "C" { |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
5 #endif |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
6 |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
7 /* A symbol table is constructed each time PyNode_Compile() is |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
8 called. The table walks the entire parse tree and identifies each |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
9 use or definition of a variable. |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
10 |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
11 The symbol table contains a dictionary for each code block in a |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
12 module: The symbol dictionary for the block. They keys of these |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
13 dictionaries are the name of all variables used or defined in the |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
14 block; the integer values are used to store several flags, |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
15 e.g. DEF_PARAM indicates that a variable is a parameter to a |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
16 function. |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16428
diff
changeset
|
17 */ |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
18 |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16428
diff
changeset
|
19 struct _symtable_entry; |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
20 |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
21 struct symtable { |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
22 int st_pass; /* pass == 1 or 2 */ |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
24752
diff
changeset
|
23 const char *st_filename; /* name of file being compiled */ |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16428
diff
changeset
|
24 struct _symtable_entry *st_cur; /* current symbol table entry */ |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16428
diff
changeset
|
25 PyObject *st_symbols; /* dictionary of symbol table entries */ |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
26 PyObject *st_stack; /* stack of namespace info */ |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
27 PyObject *st_global; /* borrowed ref to MODULE in st_symbols */ |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
28 int st_nscopes; /* number of scopes */ |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
29 int st_errors; /* number of errors */ |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
30 char *st_private; /* name of current class or NULL */ |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
31 int st_tmpname; /* temporary name counter */ |
|
16799
08d937107fe6
Improved __future__ parser; still more to do
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16781
diff
changeset
|
32 PyFutureFeatures *st_future; /* module's future features */ |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
33 }; |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
34 |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16428
diff
changeset
|
35 typedef struct _symtable_entry { |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16428
diff
changeset
|
36 PyObject_HEAD |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16428
diff
changeset
|
37 PyObject *ste_id; /* int: key in st_symbols) */ |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16428
diff
changeset
|
38 PyObject *ste_symbols; /* dict: name to flags) */ |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16428
diff
changeset
|
39 PyObject *ste_name; /* string: name of scope */ |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16428
diff
changeset
|
40 PyObject *ste_varnames; /* list of variable names */ |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16428
diff
changeset
|
41 PyObject *ste_children; /* list of child ids */ |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16428
diff
changeset
|
42 int ste_type; /* module, class, or function */ |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16428
diff
changeset
|
43 int ste_lineno; /* first line of scope */ |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16539
diff
changeset
|
44 int ste_optimized; /* true if namespace can't be optimized */ |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16428
diff
changeset
|
45 int ste_nested; /* true if scope is nested */ |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16428
diff
changeset
|
46 int ste_child_free; /* true if a child scope has free variables, |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16428
diff
changeset
|
47 including free refs to globals */ |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17132
diff
changeset
|
48 int ste_generator; /* true if namespace is a generator */ |
|
17132
55218e0495bc
Set the line number correctly for a nested function with an exec or
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16866
diff
changeset
|
49 int ste_opt_lineno; /* lineno of last exec or import * */ |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16428
diff
changeset
|
50 struct symtable *ste_table; |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16428
diff
changeset
|
51 } PySymtableEntryObject; |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16428
diff
changeset
|
52 |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
19177
diff
changeset
|
53 PyAPI_DATA(PyTypeObject) PySymtableEntry_Type; |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16428
diff
changeset
|
54 |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16428
diff
changeset
|
55 #define PySymtableEntry_Check(op) ((op)->ob_type == &PySymtableEntry_Type) |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16428
diff
changeset
|
56 |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
19177
diff
changeset
|
57 PyAPI_FUNC(PyObject *) PySymtableEntry_New(struct symtable *, |
|
16539
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16428
diff
changeset
|
58 char *, int, int); |
|
a47d93ef103a
Relax the rules for using 'from ... import *' and exec in the presence
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16428
diff
changeset
|
59 |
|
26601
cc05c2c8660e
Constify filenames and scripts. Fixes #651362.
Martin v. Löwis <martin@v.loewis.de>
parents:
24752
diff
changeset
|
60 PyAPI_FUNC(struct symtable *) PyNode_CompileSymtable(struct _node *, const char *); |
|
24752
c1eb668525e1
Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents:
19177
diff
changeset
|
61 PyAPI_FUNC(void) PySymtable_Free(struct symtable *); |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
62 |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
63 |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
64 #define TOP "global" |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
65 |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
66 /* Flags for def-use information */ |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
67 |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
68 #define DEF_GLOBAL 1 /* global stmt */ |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
69 #define DEF_LOCAL 2 /* assignment in code block */ |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
70 #define DEF_PARAM 2<<1 /* formal parameter */ |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
71 #define USE 2<<2 /* name is used */ |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
72 #define DEF_STAR 2<<3 /* parameter is star arg */ |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
73 #define DEF_DOUBLESTAR 2<<4 /* parameter is star-star arg */ |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
74 #define DEF_INTUPLE 2<<5 /* name defined in tuple in parameters */ |
| 16866 | 75 #define DEF_FREE 2<<6 /* name used but not defined in nested scope */ |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
76 #define DEF_FREE_GLOBAL 2<<7 /* free variable is actually implicit global */ |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
77 #define DEF_FREE_CLASS 2<<8 /* free variable from class's method */ |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
78 #define DEF_IMPORT 2<<9 /* assignment occurred via import */ |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
79 |
| 16866 | 80 #define DEF_BOUND (DEF_LOCAL | DEF_PARAM | DEF_IMPORT) |
| 81 | |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
82 #define TYPE_FUNCTION 1 |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
83 #define TYPE_CLASS 2 |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
84 #define TYPE_MODULE 3 |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
85 |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
86 #define LOCAL 1 |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
87 #define GLOBAL_EXPLICIT 2 |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
88 #define GLOBAL_IMPLICIT 3 |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
89 #define FREE 4 |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
90 #define CELL 5 |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
91 |
|
16781
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16539
diff
changeset
|
92 #define OPT_IMPORT_STAR 1 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16539
diff
changeset
|
93 #define OPT_EXEC 2 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16539
diff
changeset
|
94 #define OPT_BARE_EXEC 4 |
|
5a1230de436a
Preliminary support for future nested scopes
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16539
diff
changeset
|
95 |
|
16421
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
96 #ifdef __cplusplus |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
97 } |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
98 #endif |
|
aa844711463a
Move a bunch of definitions that were internal to compile.c to
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
diff
changeset
|
99 #endif /* !Py_SYMTABLE_H */ |
