MCPcopy Index your code
hub / github.com/python/cpython / ASTModuleVisitor

Class ASTModuleVisitor

Parser/asdl_c.py:1960–2029  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1958
1959
1960class ASTModuleVisitor(PickleVisitor):
1961
1962 def visitModule(self, mod):
1963 self.emit("static int", 0)
1964 self.emit("astmodule_exec(PyObject *m)", 0)
1965 self.emit("{", 0)
1966 self.emit('struct ast_state *state = get_ast_state();', 1)
1967 self.emit('if (state == NULL) {', 1)
1968 self.emit('return -1;', 2)
1969 self.emit('}', 1)
1970 self.emit('if (PyModule_AddObjectRef(m, "AST", state->AST_type) < 0) {', 1)
1971 self.emit('return -1;', 2)
1972 self.emit('}', 1)
1973 self.emit('if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) {', 1)
1974 self.emit("return -1;", 2)
1975 self.emit('}', 1)
1976 self.emit('if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) {', 1)
1977 self.emit("return -1;", 2)
1978 self.emit('}', 1)
1979 self.emit('if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) {', 1)
1980 self.emit("return -1;", 2)
1981 self.emit('}', 1)
1982 self.emit('if (PyModule_AddIntMacro(m, PyCF_OPTIMIZED_AST) < 0) {', 1)
1983 self.emit("return -1;", 2)
1984 self.emit('}', 1)
1985 for dfn in mod.dfns:
1986 self.visit(dfn)
1987 self.emit("return 0;", 1)
1988 self.emit("}", 0)
1989 self.emit("", 0)
1990 self.emit("""
1991static PyModuleDef_Slot astmodule_slots[] = {
1992 _Py_ABI_SLOT,
1993 {Py_mod_exec, astmodule_exec},
1994 {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
1995 {Py_mod_gil, Py_MOD_GIL_NOT_USED},
1996 {0, NULL}
1997};
1998
1999static struct PyModuleDef _astmodule = {
2000 PyModuleDef_HEAD_INIT,
2001 .m_name = "_ast",
2002 // The _ast module uses a per-interpreter state (PyInterpreterState.ast)
2003 .m_size = 0,
2004 .m_slots = astmodule_slots,
2005};
2006
2007PyMODINIT_FUNC
2008PyInit__ast(void)
2009{
2010 return PyModuleDef_Init(&_astmodule);
2011}
2012""".strip(), 0, reflow=False)
2013
2014 def visitProduct(self, prod, name):
2015 self.addObj(name)
2016
2017 def visitSum(self, sum, name):

Callers 1

write_sourceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…