ยปCore Development>Code coverage>Modules/symtablemodule.c

Python code coverage for Modules/symtablemodule.c

#countcontent
1n/a#include "Python.h"
2n/a
3n/a#include "code.h"
4n/a#include "Python-ast.h"
5n/a#include "symtable.h"
6n/a
7n/a#include "clinic/symtablemodule.c.h"
8n/a/*[clinic input]
9n/amodule _symtable
10n/a[clinic start generated code]*/
11n/a/*[clinic end generated code: output=da39a3ee5e6b4b0d input=f4685845a7100605]*/
12n/a
13n/a
14n/a/*[clinic input]
15n/a_symtable.symtable
16n/a
17n/a str: str
18n/a filename: object(converter='PyUnicode_FSDecoder')
19n/a startstr: str
20n/a /
21n/a
22n/aReturn symbol and scope dictionaries used internally by compiler.
23n/a[clinic start generated code]*/
24n/a
25n/astatic PyObject *
26n/a_symtable_symtable_impl(PyObject *module, const char *str,
27n/a PyObject *filename, const char *startstr)
28n/a/*[clinic end generated code: output=914b369c9b785956 input=6c615e84d5f408e3]*/
29n/a{
30n/a struct symtable *st;
31n/a PyObject *t;
32n/a int start;
33n/a
34n/a if (strcmp(startstr, "exec") == 0)
35n/a start = Py_file_input;
36n/a else if (strcmp(startstr, "eval") == 0)
37n/a start = Py_eval_input;
38n/a else if (strcmp(startstr, "single") == 0)
39n/a start = Py_single_input;
40n/a else {
41n/a PyErr_SetString(PyExc_ValueError,
42n/a "symtable() arg 3 must be 'exec' or 'eval' or 'single'");
43n/a Py_DECREF(filename);
44n/a return NULL;
45n/a }
46n/a st = Py_SymtableStringObject(str, filename, start);
47n/a Py_DECREF(filename);
48n/a if (st == NULL)
49n/a return NULL;
50n/a t = (PyObject *)st->st_top;
51n/a Py_INCREF(t);
52n/a PyMem_Free((void *)st->st_future);
53n/a PySymtable_Free(st);
54n/a return t;
55n/a}
56n/a
57n/astatic PyMethodDef symtable_methods[] = {
58n/a _SYMTABLE_SYMTABLE_METHODDEF
59n/a {NULL, NULL} /* sentinel */
60n/a};
61n/a
62n/astatic struct PyModuleDef symtablemodule = {
63n/a PyModuleDef_HEAD_INIT,
64n/a "_symtable",
65n/a NULL,
66n/a -1,
67n/a symtable_methods,
68n/a NULL,
69n/a NULL,
70n/a NULL,
71n/a NULL
72n/a};
73n/a
74n/aPyMODINIT_FUNC
75n/aPyInit__symtable(void)
76n/a{
77n/a PyObject *m;
78n/a
79n/a if (PyType_Ready(&PySTEntry_Type) < 0)
80n/a return NULL;
81n/a
82n/a m = PyModule_Create(&symtablemodule);
83n/a if (m == NULL)
84n/a return NULL;
85n/a PyModule_AddIntMacro(m, USE);
86n/a PyModule_AddIntMacro(m, DEF_GLOBAL);
87n/a PyModule_AddIntMacro(m, DEF_LOCAL);
88n/a PyModule_AddIntMacro(m, DEF_PARAM);
89n/a PyModule_AddIntMacro(m, DEF_FREE);
90n/a PyModule_AddIntMacro(m, DEF_FREE_CLASS);
91n/a PyModule_AddIntMacro(m, DEF_IMPORT);
92n/a PyModule_AddIntMacro(m, DEF_BOUND);
93n/a PyModule_AddIntMacro(m, DEF_ANNOT);
94n/a
95n/a PyModule_AddIntConstant(m, "TYPE_FUNCTION", FunctionBlock);
96n/a PyModule_AddIntConstant(m, "TYPE_CLASS", ClassBlock);
97n/a PyModule_AddIntConstant(m, "TYPE_MODULE", ModuleBlock);
98n/a
99n/a PyModule_AddIntMacro(m, LOCAL);
100n/a PyModule_AddIntMacro(m, GLOBAL_EXPLICIT);
101n/a PyModule_AddIntMacro(m, GLOBAL_IMPLICIT);
102n/a PyModule_AddIntMacro(m, FREE);
103n/a PyModule_AddIntMacro(m, CELL);
104n/a
105n/a PyModule_AddIntConstant(m, "SCOPE_OFF", SCOPE_OFFSET);
106n/a PyModule_AddIntMacro(m, SCOPE_MASK);
107n/a
108n/a if (PyErr_Occurred()) {
109n/a Py_DECREF(m);
110n/a m = 0;
111n/a }
112n/a return m;
113n/a}